From 86d33611057267a4b22c7017f5b9bd7c11934b2b Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Fri, 27 Nov 2015 22:53:17 +0300 Subject: [PATCH] preserve consistency of EditorSizeManager state when editor is modified while it's hidden --- .../openapi/editor/impl/SoftWrapModelImpl.java | 4 ++++ .../editor/impl/view/EditorSizeManager.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java index 596613e3b982..0a44bcfbca52 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java @@ -754,6 +754,10 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedInternalDo return dumpState(); } + public boolean isDirty() { + return myDirty; + } + /** * Defines generic interface for the command that may be proceeded in both 'soft wraps aware' and * 'soft wraps unaware' modes. diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorSizeManager.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorSizeManager.java index 25f0b0c0989c..763ad29cc9fd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorSizeManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorSizeManager.java @@ -70,6 +70,10 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold private int myFoldingChangeStartOffset = Integer.MAX_VALUE; private int myFoldingChangeEndOffset = Integer.MIN_VALUE; + private boolean myDirty; // true if we cannot calculate preferred size now because soft wrap model was invalidated after editor + // became hidden. myLineWidths contents is irrelevant in such a state. Previously calculated preferred size + // is kept until soft wraps will be recalculated and size calculations will become possible + private final List myDeferredRanges = new ArrayList(); private final SoftWrapAwareDocumentParsingListenerAdapter mySoftWrapChangeListener = new SoftWrapAwareDocumentParsingListenerAdapter() { @@ -179,6 +183,7 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold private int getPreferredWidth() { if (myWidthInPixels < 0) { assert !myDocument.isInBulkUpdate(); + assert !myDirty; myWidthInPixels = calculatePreferredWidth(); } validateMaxLineWithExtension(); @@ -273,6 +278,11 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold } private void doInvalidateRange(int startOffset, int endOffset) { + if (myDirty) return; + if (myEditor.getSoftWrapModel().isDirty()) { + myDirty = true; + return; + } myWidthInPixels = -1; int startVisualLine = myView.offsetToVisualLine(startOffset, false); int endVisualLine = myView.offsetToVisualLine(endOffset, true); @@ -309,6 +319,11 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold } private void onTextLayoutPerformed(int startOffset, int endOffset) { + if (myDirty) return; + if (myEditor.getSoftWrapModel().isDirty()) { + myDirty = true; + return; + } boolean purePaintingMode = myEditor.isPurePaintingMode(); boolean foldingEnabled = myEditor.getFoldingModel().isFoldingEnabled(); myEditor.setPurePaintingMode(false);