[hg] main-silver: #231646 - Show current index of match in searc...

  • From: Milutin Kristofic < >
  • To:
  • Subject: [hg] main-silver: #231646 - Show current index of match in searc...
  • Date: Thu, 05 Sep 2013 12:33:59 -0700

changeset e452d8056ce2 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/e452d8056ce2
description:
        #231646 - Show current index of match in searchbar - performance 
tweaks

diffstat:

 editor.search/src/org/netbeans/modules/editor/search/SearchBar.java |  30 
++++++---
 1 files changed, 19 insertions(+), 11 deletions(-)

diffs (88 lines):

diff --git 
a/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java 
b/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java
--- a/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java
+++ b/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java
@@ -118,6 +118,7 @@
     private final JToggleButton wrapAround;
     private final JButton closeButton;
     private final JLabel matches;
+    private int numOfMatches = -1;
     private SearchProperties searchProps = 
SearchPropertiesSupport.getSearchProperties();
     private boolean popupMenuWasCanceled = false;
     private Rectangle actualViewPort;
@@ -454,9 +455,11 @@
 
             @Override
             public void caretUpdate(CaretEvent e) {
-                int num = SearchBar.getInstance().showNumberOfMatches(null, 
-1);
+                if (SearchBar.getInstance().isVisible()) {
+                    int num = SearchBar.getInstance().getNumOfMatches();
                 SearchBar.getInstance().showNumberOfMatches(null, num);
             }
+            }
         };
     }
 
@@ -910,23 +913,27 @@
         find(false);
     }
 
+    public int getNumOfMatches() {
+        return numOfMatches;
+    }
+
     /**
      * @param findSupport if null EditorFindSupport.getInstance() is used
-     * @param numOfMatches if numOfMatches < 0, calculate numOfMatches and 
position, else show numOfMatches.
+     * @param numMatches if numOfMatches < 0, calculate numOfMatches and 
position, else show numOfMatches.
      * @return 
      */
-    public int showNumberOfMatches(EditorFindSupport findSupport, int 
numOfMatches) {
+    public int showNumberOfMatches(EditorFindSupport findSupport, int 
numMatches) {
         if (findSupport == null) {
             findSupport = EditorFindSupport.getInstance();
         }
         int pos = 0;
-        if (numOfMatches < 0) {
+        if (numMatches < 0) {
             int currentpos = getActualTextComponent().getSelectionStart();
             try {
                 int[] blocks = findSupport.getBlocks(new int[]{-1, -1}, 
getActualTextComponent().getDocument(), 0, 
getActualTextComponent().getDocument().getLength());
                 for (int i : blocks) {
                     if (i > 0) {
-                        numOfMatches++;
+                        numMatches++;
                         if (i < currentpos) {
                             pos++;
                         }
@@ -935,24 +942,25 @@
             } catch (BadLocationException ex) {
                 Exceptions.printStackTrace(ex);
             }
-            numOfMatches = numOfMatches == 0 ? 0 : (numOfMatches + 1) / 2;
+            numMatches = numMatches == 0 ? 0 : (numMatches + 1) / 2;
             pos = (pos == 0 ? 0 : (pos + 1) / 2) + 1;
             
         }
         if (incSearchTextField.getText().isEmpty()) {
             Mnemonics.setLocalizedText(matches, ""); //NOI18N
-        } else if (numOfMatches == 0) {
+        } else if (numMatches == 0) {
             Mnemonics.setLocalizedText(matches, 
NbBundle.getMessage(SearchBar.class, "0_matches")); //NOI18N
-        } else if (numOfMatches == 1) {
+        } else if (numMatches == 1) {
             Mnemonics.setLocalizedText(matches, 
NbBundle.getMessage(SearchBar.class, "1_matches")); //NOI18N
         } else {
             if (pos == 0) {
-                Mnemonics.setLocalizedText(matches, 
NbBundle.getMessage(SearchBar.class, "n_matches", numOfMatches)); //NOI18N
+                Mnemonics.setLocalizedText(matches, 
NbBundle.getMessage(SearchBar.class, "n_matches", numMatches)); //NOI18N
             } else {
-                Mnemonics.setLocalizedText(matches, 
NbBundle.getMessage(SearchBar.class, "i_n_matches", pos, numOfMatches)); 
//NOI18N
+                Mnemonics.setLocalizedText(matches, 
NbBundle.getMessage(SearchBar.class, "i_n_matches", pos, numMatches)); 
//NOI18N
             }
         }
-        return numOfMatches;
+        this.numOfMatches  = numMatches;
+        return numMatches;
     }
 
     private void find(boolean next) {

[hg] main-silver: #231646 - Show current index of match in searc...

Milutin Kristofic 09/05/2013

<Possible follow-up(s)>

[hg] main-silver: #231646 - Show current index of match in searc...

Milutin Kristofic 09/05/2013

[hg] main-silver: #231646 - Show current index of match in searc...

Milutin Kristofic 09/05/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close