diff: update foldings in a single batch operation

This fixes completion popup blinking on typing
If we destroy and install foldings in separate operaions, caret's visual position jumps back and forth, triggering popup close
This commit is contained in:
Aleksey Pivovarov
2016-07-04 15:25:04 +03:00
parent 64b96da1d9
commit 9f3ffa0619
3 changed files with 28 additions and 18 deletions
@@ -99,6 +99,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer {
@CalledInAwt
protected void onDispose() {
destroyChangedBlocks();
myFoldingModel.destroy();
super.onDispose();
}
@@ -225,6 +226,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer {
private Runnable apply(@NotNull final CompareData data) {
return () -> {
myFoldingModel.updateContext(myRequest, getFoldingModelSettings());
clearDiffPresentation();
myIsContentsEqual = data.isContentsEqual();
@@ -253,6 +255,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer {
private Runnable applyNotification(@Nullable final JComponent notification) {
return () -> {
clearDiffPresentation();
myFoldingModel.destroy();
if (notification != null) myPanel.addNotification(notification);
};
}
@@ -290,8 +293,6 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer {
}
myInvalidDiffChanges.clear();
myFoldingModel.destroy();
myContentPanel.repaintDivider();
myStatusPanel.update();
}
@@ -88,6 +88,7 @@ public abstract class ThreesideTextDiffViewerEx extends ThreesideTextDiffViewer
@CalledInAwt
protected void onDispose() {
destroyChangedBlocks();
myFoldingModel.destroy();
super.onDispose();
}
@@ -119,6 +120,7 @@ public abstract class ThreesideTextDiffViewerEx extends ThreesideTextDiffViewer
protected Runnable applyNotification(@Nullable final JComponent notification) {
return () -> {
clearDiffPresentation();
myFoldingModel.destroy();
if (notification != null) myPanel.addNotification(notification);
};
}
@@ -135,7 +137,6 @@ public abstract class ThreesideTextDiffViewerEx extends ThreesideTextDiffViewer
@CalledInAwt
protected void destroyChangedBlocks() {
myFoldingModel.destroy();
}
//
@@ -100,12 +100,21 @@ public class FoldingModelSupport {
@NotNull final Settings settings) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (changedLines == null) return;
if (settings.range == -1) return;
for (FoldedBlock folding : getFoldedBlocks()) {
folding.destroyHighlighter();
}
runBatchOperation(() -> {
FoldingBuilder builder = new FoldingBuilder(context, settings);
builder.build(changedLines);
for (FoldedBlock folding : getFoldedBlocks()) {
folding.destroyFolding();
}
myFoldings.clear();
if (changedLines != null && settings.range != -1) {
FoldingBuilder builder = new FoldingBuilder(context, settings);
builder.build(changedLines);
}
});
updateLineNumbers(true);
@@ -244,23 +253,15 @@ public class FoldingModelSupport {
}
public void destroy() {
for (int i = 0; i < myCount; i++) {
destroyFoldings(i);
}
for (FoldedBlock folding : getFoldedBlocks()) {
folding.destroyHighlighter();
}
myFoldings.clear();
}
private void destroyFoldings(final int index) {
final FoldingModelEx model = myEditors[index].getFoldingModel();
model.runBatchFoldingOperation(() -> {
runBatchOperation(() -> {
for (FoldedBlock folding : getFoldedBlocks()) {
FoldRegion region = folding.getRegion(index);
if (region != null) model.removeFoldRegion(region);
folding.destroyFolding();
}
myFoldings.clear();
});
}
@@ -615,6 +616,13 @@ public class FoldingModelSupport {
}
}
public void destroyFolding() {
for (int i = 0; i < myCount; i++) {
FoldRegion region = myRegions[i];
if (region != null) myEditors[i].getFoldingModel().removeFoldRegion(region);
}
}
public void destroyHighlighter() {
for (RangeHighlighter highlighter : myHighlighters) {
highlighter.dispose();