From 43d812431a162927be97756cce2fb563c1deb4b3 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Wed, 23 Aug 2017 20:11:13 +0300 Subject: [PATCH] IDEA-177899 Exception thrown when removing valid FoldRegion --- .../openapi/editor/impl/FoldingModelImpl.java | 6 ++---- .../openapi/editor/impl/EditorStressTest.java | 14 +++++++++++++- .../intellij/openapi/editor/impl/FoldingTest.java | 6 ++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java index f9f73570d28e..1320c74bdbcb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java @@ -315,10 +315,8 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedInternalDocu } FoldRegion[] regions = getAllFoldRegions(); for (FoldRegion region : regions) { - if (!region.isExpanded()) { - notifyListenersOnFoldRegionStateChange(region); - myFoldRegionsProcessed = true; - } + if (!region.isExpanded()) notifyListenersOnFoldRegionStateChange(region); + region.dispose(); } doClearFoldRegions(); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorStressTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorStressTest.java index dc90507e1259..e5b0322cfe23 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorStressTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorStressTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.FoldingModel; import com.intellij.openapi.editor.Inlay; import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.editor.ex.FoldingModelEx; import com.intellij.openapi.util.Disposer; import javax.swing.*; @@ -45,6 +46,7 @@ public class EditorStressTest extends AbstractEditorTest { new RemoveFoldRegion(), new CollapseFoldRegion(), new ExpandFoldRegion(), + new ClearFoldRegions(), new ChangeBulkModeState(), new ChangeEditorVisibility(), new AddInlay(), @@ -197,6 +199,16 @@ public class EditorStressTest extends AbstractEditorTest { } } + private static class ClearFoldRegions implements Action { + @Override + public void perform(final EditorEx editor, Random random) { + DocumentEx document = editor.getDocument(); + if (document.isInBulkUpdate()) return; + FoldingModelEx foldingModel = editor.getFoldingModel(); + foldingModel.runBatchFoldingOperation(() -> foldingModel.clearFoldRegions()); + } + } + private static class ChangeBulkModeState implements Action { @Override public void perform(EditorEx editor, Random random) { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java index 443633ae6f9b..0b6363117d5f 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java @@ -357,4 +357,10 @@ public class FoldingTest extends AbstractEditorTest { WriteCommandAction.runWriteCommandAction(ourProject, () -> myEditor.getDocument().deleteString(15, 20)); Assert.assertArrayEquals(new FoldRegion[]{inner}, myModel.fetchTopLevel()); } + + public void testClearingInvalidatesFoldRegions() { + FoldRegion region = addCollapsedFoldRegion(5, 10, "..."); + myModel.runBatchFoldingOperation(() -> myModel.clearFoldRegions()); + assertFalse(region.isValid()); + } }