You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/06/12 14:07:50 UTC

[groovy] branch master updated: Trivial tweak: avoid redundant operations when text updated

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 bd56a6b  Trivial tweak: avoid redundant operations when text updated
bd56a6b is described below

commit bd56a6b84e5d163a215c5e16537d7ec81e26ac6e
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jun 12 22:07:32 2021 +0800

    Trivial tweak: avoid redundant operations when text updated
---
 .../src/main/groovy/groovy/console/ui/ConsoleTextEditor.java  | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleTextEditor.java b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleTextEditor.java
index 4b497f7..ae846c1 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleTextEditor.java
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleTextEditor.java
@@ -165,6 +165,9 @@ public class ConsoleTextEditor extends JScrollPane {
         // add a document listener, to hint whether the line number gutter has to be repainted
         // when the number of lines changes
         doc.addDocumentListener(new DocumentListener() {
+            private Preferences preferences;
+            private int width;
+
             @Override
             public void insertUpdate(DocumentEvent documentEvent) {
                 documentChangedSinceLastRepaint = true;
@@ -178,8 +181,12 @@ public class ConsoleTextEditor extends JScrollPane {
             @Override
             public void changedUpdate(DocumentEvent documentEvent) {
                 documentChangedSinceLastRepaint = true;
-                int width = 3 * Preferences.userNodeForPackage(Console.class).getInt("fontSize", 12);
-                numbersPanel.setPreferredSize(new Dimension(width, width));
+                if (null == preferences) preferences = Preferences.userNodeForPackage(Console.class);
+                int width = 3 * preferences.getInt("fontSize", 12);
+                if (width != this.width) {
+                    this.width = width;
+                    numbersPanel.setPreferredSize(new Dimension(width, width));
+                }
             }
         });