prevent fold regions from 'disappearing' if no one references them

supposedly fixes EA-107809 - AIOOBE: TIntArrayList.insert
This commit is contained in:
Dmitry Batrak
2018-03-20 16:22:31 +03:00
parent 0ab773efd8
commit 472d029969
2 changed files with 26 additions and 2 deletions
@@ -7,11 +7,12 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.FoldingGroup;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.util.Getter;
import com.intellij.util.DocumentUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class FoldRegionImpl extends RangeMarkerImpl implements FoldRegion {
class FoldRegionImpl extends RangeMarkerImpl implements FoldRegion, Getter<FoldRegionImpl> {
private boolean myIsExpanded;
private final EditorImpl myEditor;
private final String myPlaceholderText;
@@ -65,6 +66,11 @@ class FoldRegionImpl extends RangeMarkerImpl implements FoldRegion {
}
}
@Override
public FoldRegionImpl get() {
return this;
}
private static void doSetExpanded(boolean expanded, FoldingModelImpl foldingModel, FoldRegion region, boolean notify) {
if (expanded) {
foldingModel.expandFoldRegion(region, notify);
@@ -15,6 +15,7 @@ import com.intellij.openapi.editor.ex.FoldingModelEx;
import com.intellij.openapi.editor.ex.PrioritizedInternalDocumentListener;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Getter;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.ModificationTracker;
import com.intellij.util.DocumentUtil;
@@ -59,7 +60,24 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedInternalDocu
myIsFoldingEnabled = true;
myIsBatchFoldingProcessing = false;
myDoNotCollapseCaret = false;
myRegionTree = new RangeMarkerTree<>(editor.getDocument());
myRegionTree = new RangeMarkerTree<FoldRegionImpl>(editor.getDocument()) {
@NotNull
@Override
protected RMNode<FoldRegionImpl> createNewNode(@NotNull FoldRegionImpl key,
int start,
int end,
boolean greedyToLeft,
boolean greedyToRight,
boolean stickingToRight,
int layer) {
return new RMNode<FoldRegionImpl>(this, key, start, end, greedyToLeft, greedyToRight, stickingToRight) {
@Override
protected Getter<FoldRegionImpl> createGetter(@NotNull FoldRegionImpl region) {
return region;
}
};
}
};
myFoldTree = new FoldRegionsTree(myRegionTree) {
@Override
protected boolean isFoldingEnabled() {