Skip to content

Commit 0fc70bb

Browse files
committed
Remove document listener from *old* document on setDocument()
UpdateDocumentListener is added to document but not always removed in ProjectionViewer, regression introduced by commit 1848058 This fixes remaining possible leak, where *multiple* documents were used in ProjectionViewer. See eclipse-jdt/eclipse.jdt.ui#2532
1 parent 6877297 commit 0fc70bb

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ public void setDocument(IDocument document, IAnnotationModel annotationModel, in
400400
}
401401

402402
if (fProjectionAnnotationModel != null) {
403+
removeDocumentUpdateListener();
403404
wasProjectionEnabled= removeProjectionAnnotationModel(getVisualAnnotationModel()) != null;
404405
fProjectionAnnotationModel= null;
405406
}
@@ -413,6 +414,15 @@ public void setDocument(IDocument document, IAnnotationModel annotationModel, in
413414

414415
}
415416

417+
private void removeDocumentUpdateListener() {
418+
if (fUpdateDocumentListener != null) {
419+
IDocument document= getDocument();
420+
if (document != null) {
421+
document.removeDocumentListener(fUpdateDocumentListener);
422+
}
423+
}
424+
}
425+
416426
@Override
417427
protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotationModel) {
418428
IAnnotationModel model= super.createVisualAnnotationModel(annotationModel);
@@ -554,10 +564,7 @@ public final void disableProjection() {
554564
super.setVisibleRegion(fVisibleRegionDuringProjection.getOffset(), fVisibleRegionDuringProjection.getLength());
555565
fVisibleRegionDuringProjection= null;
556566
}
557-
IDocument document= getDocument();
558-
if (document != null) {
559-
document.removeDocumentListener(fUpdateDocumentListener);
560-
}
567+
removeDocumentUpdateListener();
561568
}
562569
}
563570

@@ -1480,12 +1487,7 @@ private boolean willAutoExpand(Position position, int offset, int length) {
14801487
@Override
14811488
protected void handleDispose() {
14821489
fWasProjectionEnabled= false;
1483-
if (fUpdateDocumentListener != null) {
1484-
IDocument document= getDocument();
1485-
if (document != null) {
1486-
document.removeDocumentListener(fUpdateDocumentListener);
1487-
}
1488-
}
1490+
removeDocumentUpdateListener();
14891491
super.handleDispose();
14901492
}
14911493

0 commit comments

Comments
 (0)