IDEA-177899 Exception thrown when removing valid FoldRegion

This commit is contained in:
Dmitry Batrak
2017-08-23 20:12:12 +03:00
parent 90eb84050f
commit 43d812431a
3 changed files with 21 additions and 5 deletions
@@ -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();
}
@@ -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) {
@@ -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());
}
}