lst: do not update RangeHighlighters inside EditorImpl.paint() call

EA-82762 - assert: EditorView.getPreferredHeight
This commit is contained in:
Aleksey Pivovarov
2016-11-21 17:56:31 +03:00
committed by Aleksey Pivovarov
parent 4981fa3406
commit 42dcb2b713
@@ -34,10 +34,7 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.diff.FilesTooBigForDiffException; import com.intellij.util.diff.FilesTooBigForDiffException;
import org.jetbrains.annotations.*; import org.jetbrains.annotations.*;
import java.util.ArrayList; import java.util.*;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;
import static com.intellij.diff.util.DiffUtil.getLineCount; import static com.intellij.diff.util.DiffUtil.getLineCount;
import static com.intellij.openapi.localVcs.UpToDateLineNumberProvider.ABSENT_LINE_NUMBER; import static com.intellij.openapi.localVcs.UpToDateLineNumberProvider.ABSENT_LINE_NUMBER;
@@ -65,7 +62,11 @@ public abstract class LineStatusTrackerBase {
private boolean myAnathemaThrown; private boolean myAnathemaThrown;
private boolean myReleased; private boolean myReleased;
@NotNull private List<Range> myRanges; @NotNull private List<Range> myRanges = Collections.emptyList();
// operation delayed till the end of write action
@NotNull private final Set<Range> myToBeDestroyedRanges = ContainerUtil.newIdentityTroveSet();
@NotNull private final Set<Range> myToBeInstalledRanges = ContainerUtil.newIdentityTroveSet();
@Nullable private DirtyRange myDirtyRange; @Nullable private DirtyRange myDirtyRange;
@@ -82,8 +83,6 @@ public abstract class LineStatusTrackerBase {
myApplicationListener = new MyApplicationListener(); myApplicationListener = new MyApplicationListener();
myApplication.addApplicationListener(myApplicationListener); myApplication.addApplicationListener(myApplicationListener);
myRanges = new ArrayList<>();
myVcsDocument = new DocumentImpl("", true); myVcsDocument = new DocumentImpl("", true);
myVcsDocument.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE); myVcsDocument.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
} }
@@ -161,9 +160,15 @@ public abstract class LineStatusTrackerBase {
private void destroyRanges() { private void destroyRanges() {
removeAnathema(); removeAnathema();
for (Range range : myRanges) { for (Range range : myRanges) {
range.invalidate();
disposeHighlighter(range);
}
for (Range range : myToBeDestroyedRanges) {
disposeHighlighter(range); disposeHighlighter(range);
} }
myRanges = Collections.emptyList(); myRanges = Collections.emptyList();
myToBeDestroyedRanges.clear();
myToBeInstalledRanges.clear();
myDirtyRange = null; myDirtyRange = null;
} }
@@ -183,7 +188,6 @@ public abstract class LineStatusTrackerBase {
@CalledInAwt @CalledInAwt
private void disposeHighlighter(@NotNull Range range) { private void disposeHighlighter(@NotNull Range range) {
try { try {
range.invalidate();
RangeHighlighter highlighter = range.getHighlighter(); RangeHighlighter highlighter = range.getHighlighter();
if (highlighter != null) { if (highlighter != null) {
range.setHighlighter(null); range.setHighlighter(null);
@@ -311,10 +315,25 @@ public abstract class LineStatusTrackerBase {
} }
} }
@CalledInAwt
private void updateRangeHighlighters() {
myToBeInstalledRanges.removeAll(myToBeDestroyedRanges);
for (Range range : myToBeDestroyedRanges) {
disposeHighlighter(range);
}
for (Range range : myToBeInstalledRanges) {
createHighlighter(range);
}
myToBeDestroyedRanges.clear();
myToBeInstalledRanges.clear();
}
private class MyApplicationListener extends ApplicationAdapter { private class MyApplicationListener extends ApplicationAdapter {
@Override @Override
public void afterWriteActionFinished(@NotNull Object action) { public void afterWriteActionFinished(@NotNull Object action) {
updateRanges(); updateRanges();
updateRangeHighlighters();
} }
} }
@@ -484,11 +503,10 @@ public abstract class LineStatusTrackerBase {
myRanges.addAll(rangesAfter); myRanges.addAll(rangesAfter);
for (Range range : changedRanges) { for (Range range : changedRanges) {
disposeHighlighter(range); range.invalidate();
}
for (Range range : newChangedRanges) {
createHighlighter(range);
} }
myToBeDestroyedRanges.addAll(changedRanges);
myToBeInstalledRanges.addAll(newChangedRanges);
if (myRanges.isEmpty()) { if (myRanges.isEmpty()) {
fireFileUnchanged(); fireFileUnchanged();
@@ -725,6 +743,7 @@ public abstract class LineStatusTrackerBase {
int beforeTotalLines = getLineCount(myDocument) - shift; int beforeTotalLines = getLineCount(myDocument) - shift;
doUpdateRanges(beforeChangedLine1, beforeChangedLine2, shift, beforeTotalLines); doUpdateRanges(beforeChangedLine1, beforeChangedLine2, shift, beforeTotalLines);
updateRangeHighlighters();
} }
}); });
} }