diff options
-rw-r--r-- | org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java index df1e7b9401e..8bb1e7a5598 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java @@ -36,7 +36,9 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.core.runtime.Assert; import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ISynchronizable; import org.eclipse.jface.text.ITextPresentationListener; @@ -123,17 +125,17 @@ public class InlinedAnnotationSupport implements StyledTextLineSpacingProvider { * Class to track start/end offset of visible lines. * */ - private class VisibleLines implements IViewportListener { + private class VisibleLines implements IViewportListener, IDocumentListener { private int startOffset; - private int endOffset; + private Integer endOffset; public VisibleLines() { fViewer.getTextWidget().getDisplay().asyncExec(() -> { - startOffset= getInclusiveTopIndexStartOffset(); - endOffset= getExclusiveBottomIndexEndOffset(); + compute(); }); + fViewer.getDocument().addDocumentListener(this); } @Override @@ -141,6 +143,17 @@ public class InlinedAnnotationSupport implements StyledTextLineSpacingProvider { compute(); } + @Override + public void documentAboutToBeChanged(DocumentEvent event) { + endOffset= null; + } + + @Override + public void documentChanged(DocumentEvent event) { + // Do nothing + } + + @SuppressWarnings("boxing") private void compute() { startOffset= getInclusiveTopIndexStartOffset(); endOffset= getExclusiveBottomIndexEndOffset(); @@ -194,9 +207,22 @@ public class InlinedAnnotationSupport implements StyledTextLineSpacingProvider { * @return <code>true</code> if the given offset is in visible lines and <code>false</code> * otherwise. */ - public boolean isInVisibleLines(int offset) { + @SuppressWarnings("boxing") + boolean isInVisibleLines(int offset) { + if (endOffset == null) { + endOffset= getExclusiveBottomIndexEndOffset(); + } return offset >= startOffset && offset <= endOffset; } + + /** + * Uninstall visible lines + */ + void uninstall() { + if (fViewer != null && fViewer.getDocument() != null) { + fViewer.getDocument().removeDocumentListener(this); + } + } } private class MouseTracker implements MouseTrackListener, MouseMoveListener, MouseListener { @@ -353,6 +379,10 @@ public class InlinedAnnotationSupport implements StyledTextLineSpacingProvider { } fViewer.removeViewportListener(visibleLines); } + if (visibleLines != null) { + visibleLines.uninstall(); + visibleLines= null; + } fViewer= null; fPainter= null; } |