groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] branch master updated: Fix failing to disable matching highlighter
Date Tue, 12 Feb 2019 14:53:50 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 96a7440  Fix failing to disable matching highlighter
96a7440 is described below

commit 96a74404d790d0cab54ee15bc639cb92ac5ce578
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Tue Feb 12 22:50:20 2019 +0800

    Fix failing to disable matching highlighter
---
 .../main/groovy/groovy/ui/ConsoleTextEditor.java    | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/ConsoleTextEditor.java b/subprojects/groovy-console/src/main/groovy/groovy/ui/ConsoleTextEditor.java
index 41fcccf..4adf7fa 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/ConsoleTextEditor.java
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/ConsoleTextEditor.java
@@ -331,18 +331,25 @@ public class ConsoleTextEditor extends JScrollPane {
             DocumentFilter documentFilter = (DocumentFilter) clazz.getConstructor(doc.getClass()).newInstance(doc);
             doc.setDocumentFilter(documentFilter);
 
+            disableMatchingHighlighter();
             if (documentFilter instanceof SmartDocumentFilter) {
                 final SmartDocumentFilter smartDocumentFilter = (SmartDocumentFilter) documentFilter;
-
-                for (CaretListener cl : textEditor.getCaretListeners()) {
-                    if (cl instanceof MatchingHighlighter) {
-                        textEditor.removeCaretListener(cl);
-                    }
-                }
-                textEditor.addCaretListener(new MatchingHighlighter(smartDocumentFilter,
textEditor));
+                enableMatchingHighlighter(smartDocumentFilter);
             }
         } catch (ReflectiveOperationException e) {
             e.printStackTrace();
         }
     }
+
+    private void enableMatchingHighlighter(SmartDocumentFilter smartDocumentFilter) {
+        textEditor.addCaretListener(new MatchingHighlighter(smartDocumentFilter, textEditor));
+    }
+
+    private void disableMatchingHighlighter() {
+        for (CaretListener cl : textEditor.getCaretListeners()) {
+            if (cl instanceof MatchingHighlighter) {
+                textEditor.removeCaretListener(cl);
+            }
+        }
+    }
 }


Mime
View raw message