diff --git a/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java b/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java index a99a85541dd..576c0212ec9 100644 --- a/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java +++ b/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java @@ -400,6 +400,7 @@ public void setDocument(IDocument document, IAnnotationModel annotationModel, in } if (fProjectionAnnotationModel != null) { + removeDocumentUpdateListener(); wasProjectionEnabled= removeProjectionAnnotationModel(getVisualAnnotationModel()) != null; fProjectionAnnotationModel= null; } @@ -413,6 +414,15 @@ public void setDocument(IDocument document, IAnnotationModel annotationModel, in } + private void removeDocumentUpdateListener() { + if (fUpdateDocumentListener != null) { + IDocument document= getDocument(); + if (document != null) { + document.removeDocumentListener(fUpdateDocumentListener); + } + } + } + @Override protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotationModel) { IAnnotationModel model= super.createVisualAnnotationModel(annotationModel); @@ -554,10 +564,7 @@ public final void disableProjection() { super.setVisibleRegion(fVisibleRegionDuringProjection.getOffset(), fVisibleRegionDuringProjection.getLength()); fVisibleRegionDuringProjection= null; } - IDocument document= getDocument(); - if (document != null) { - document.removeDocumentListener(fUpdateDocumentListener); - } + removeDocumentUpdateListener(); } } @@ -1480,12 +1487,7 @@ private boolean willAutoExpand(Position position, int offset, int length) { @Override protected void handleDispose() { fWasProjectionEnabled= false; - if (fUpdateDocumentListener != null) { - IDocument document= getDocument(); - if (document != null) { - document.removeDocumentListener(fUpdateDocumentListener); - } - } + removeDocumentUpdateListener(); super.handleDispose(); }