diff --git a/platform/openide.text/src/org/openide/text/CloneableEditorSupport.java b/platform/openide.text/src/org/openide/text/CloneableEditorSupport.java index b562ed574327..665b757d5dc5 100644 --- a/platform/openide.text/src/org/openide/text/CloneableEditorSupport.java +++ b/platform/openide.text/src/org/openide/text/CloneableEditorSupport.java @@ -213,6 +213,7 @@ public abstract class CloneableEditorSupport extends CloneableOpenSupport { private boolean annotationsLoaded; private DocFilter docFilter; + private DocumentOpenClose.DocumentRef filteredDocRef; private final Object checkModificationLock = new Object(); @@ -493,16 +494,20 @@ final void addDocListener(Document d) { if (Boolean.TRUE.equals(d.getProperty("supportsModificationListener"))) { // NOI18N d.putProperty("modificationListener", getListener()); // NOI18N } - - if (d instanceof AbstractDocument) { - AbstractDocument aDoc = (AbstractDocument) d; - DocumentFilter origFilter = aDoc.getDocumentFilter(); - docFilter = new DocFilter(origFilter); - aDoc.setDocumentFilter(docFilter); - } else { // Put property for non-AD - DocumentFilter origFilter = (DocumentFilter) d.getProperty(DocumentFilter.class); - docFilter = new DocFilter(origFilter); - d.putProperty(DocumentFilter.class, docFilter); + DocFilter df = docFilter; + if (df == null || df.origDocument != openClose.docRef) { + if (d instanceof AbstractDocument) { + AbstractDocument aDoc = (AbstractDocument) d; + DocumentFilter origFilter = aDoc.getDocumentFilter(); + docFilter = new DocFilter(origFilter, openClose.docRef); + aDoc.setDocumentFilter(docFilter); + } else { // Put property for non-AD + DocumentFilter origFilter = (DocumentFilter) d.getProperty(DocumentFilter.class); + docFilter = new DocFilter(origFilter, openClose.docRef); + d.putProperty(DocumentFilter.class, docFilter); + } + } else { + df.docFilterDisabled = false; } d.addDocumentListener(getListener()); } @@ -511,15 +516,9 @@ final void removeDocListener(Document d) { if (Boolean.TRUE.equals(d.getProperty("supportsModificationListener"))) { // NOI18N d.putProperty("modificationListener", null); // NOI18N } - - if (docFilter != null) { - if (d instanceof AbstractDocument) { - AbstractDocument aDoc = (AbstractDocument) d; - aDoc.setDocumentFilter(docFilter.origFilter); - } else { // Put property for non-AD - d.putProperty(DocumentFilter.class, docFilter.origFilter); - } - docFilter = null; + DocFilter df = docFilter; + if (df != null) { + df.docFilterDisabled = true; } d.removeDocumentListener(getListener()); } @@ -2325,14 +2324,17 @@ public void run() { private final class DocFilter extends DocumentFilter { final DocumentFilter origFilter; + final Reference origDocument; + boolean docFilterDisabled; - DocFilter(DocumentFilter origFilter) { + DocFilter(DocumentFilter origFilter, Reference origDocument) { this.origFilter = origFilter; + this.origDocument = origDocument; } @Override public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { - boolean origModified = checkModificationAllowed(offset); + boolean origModified = docFilterDisabled || checkModificationAllowed(offset); boolean success = false; try { if (origFilter != null) { @@ -2352,7 +2354,7 @@ public void insertString(FilterBypass fb, int offset, String string, AttributeSe @Override public void remove(FilterBypass fb, int offset, int length) throws BadLocationException { - boolean origModified = checkModificationAllowed(offset); + boolean origModified = docFilterDisabled || checkModificationAllowed(offset); boolean success = false; try { if (origFilter != null) { @@ -2372,7 +2374,7 @@ public void remove(FilterBypass fb, int offset, int length) throws BadLocationEx @Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { - boolean origModified = checkModificationAllowed(offset); + boolean origModified = docFilterDisabled || checkModificationAllowed(offset); boolean success = false; try { if (origFilter != null) { diff --git a/platform/openide.text/src/org/openide/text/DocumentOpenClose.java b/platform/openide.text/src/org/openide/text/DocumentOpenClose.java index c7b0a6c8c03c..5e043ebf997c 100644 --- a/platform/openide.text/src/org/openide/text/DocumentOpenClose.java +++ b/platform/openide.text/src/org/openide/text/DocumentOpenClose.java @@ -1026,7 +1026,7 @@ public String toString() { } - private final class DocumentRef extends WeakReference implements Runnable { + final class DocumentRef extends WeakReference implements Runnable { public DocumentRef(StyledDocument doc) { super(doc, org.openide.util.Utilities.activeReferenceQueue());