b=512643; FAYT should be smarter when there are no current matches; r=gavin
authorVladimir Vukicevic <vladimir@pobox.com>
Tue, 01 Sep 2009 22:52:05 -0700
changeset 32150 97994f5cc1c6b23aee088bb4345e7c375eb8f85d
parent 32149 00d2664f70d4b50ee4d82681cc525eaa98b4265f
child 32151 f598eea894f1353805ef4eb01088f7f7a8b7be1f
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs512643
milestone1.9.3a1pre
b=512643; FAYT should be smarter when there are no current matches; r=gavin
toolkit/content/widgets/findbar.xml
--- a/toolkit/content/widgets/findbar.xml
+++ b/toolkit/content/widgets/findbar.xml
@@ -389,16 +389,18 @@
         this._typeAheadCaseSensitive =
           prefsvc.getIntPref("accessibility.typeaheadfind.casesensitive");
 
         // Convenience
         this.nsITypeAheadFind = Components.interfaces.nsITypeAheadFind;
         this.nsISelectionController = Components.interfaces.nsISelectionController;
         this._findSelection = this.nsISelectionController.SELECTION_FIND;
 
+        this._findResetTimeout = -1;
+
         // Make sure the FAYT keypress listener is attached by initializing the
         // browser property
         setTimeout(function(aSelf) { aSelf.browser = aSelf.browser; }, 0, this);
       ]]></constructor>
 
       <destructor><![CDATA[
         this.destroy();
       ]]></destructor>
@@ -1125,16 +1127,18 @@
             this._fastFindStr =
               stringsBundle.GetStringFromName("FastFindLabel");
             this._fastFindLinksStr =
               stringsBundle.GetStringFromName("FastFindLinksLabel");
             this._caseSensitiveStr =
               stringsBundle.GetStringFromName("CaseSensitive");
           }
 
+          this._findFailedString = null;
+
           this._updateFindUI();
           if (this.hidden) {
             this.hidden = false;
 
             this._updateStatusUI(this.nsITypeAheadFind.FIND_FOUND);
             return true;
           }
           return false;
@@ -1511,32 +1515,56 @@
             this._currentWindow = this.browser.fastFind.currentWindow;
           }
         ]]></body>
       </method>
 
       <method name="_find">
         <parameter name="aValue"/>
         <body><![CDATA[
-          var val = aValue || this._findField.value
+          var val = aValue || this._findField.value;
+          var res = this.nsITypeAheadFind.FIND_NOTFOUND;
 
-          this._enableFindButtons(val);
-          if (this.getElement("highlight").checked)
-            this._setHighlightTimeout();
+          // Only search on input if we don't have a last-failed string,
+          // or if the current search string doesn't start with it.
+          if (this._findFailedString == null ||
+              val.indexOf(this._findFailedString) != 0)
+          {
+            this._enableFindButtons(val);
+            if (this.getElement("highlight").checked)
+              this._setHighlightTimeout();
 
-          this._updateCaseSensitivity(val);
+            this._updateCaseSensitivity(val);
+
+            var fastFind = this.browser.fastFind;
+            res = fastFind.find(val, this._findMode == this.FIND_LINKS);
 
-          var fastFind = this.browser.fastFind;
-          var res = fastFind.find(val, this._findMode == this.FIND_LINKS);
-          this._updateFoundLink(res);
-          this._updateStatusUI(res, false);
+            this._updateFoundLink(res);
+            this._updateStatusUI(res, false);
+
+            if (res == this.nsITypeAheadFind.FIND_NOTFOUND)
+              this._findFailedString = val;
+            else
+              this._findFailedString = null;
+          }
 
           if (this._findMode != this.FIND_NORMAL)
             this._setFindCloseTimeout();
 
+          if (this._findResetTimeout != -1)
+            clearTimeout(this._findResetTimeout);
+
+          // allow a search to happen on input again after a second has
+          // expired since the previous input, to allow for dynamic
+          // content and/or page loading
+          this._findResetTimeout = setTimeout(function(self) {
+						  self._findFailedString = null;
+						  self._findResetTimeout = -1; },
+					      1000, this);
+
           return res;
         ]]></body>
       </method>
 
       <method name="_flash">
         <body><![CDATA[
           if (this._flashFindBarCount === undefined)
             this._flashFindBarCount = this._initialFlashFindBarCount;
@@ -1708,16 +1736,19 @@
         <parameter name="aFindPrevious"/>
         <body><![CDATA[
           var findString = this._browser.fastFind.searchString || this._findField.value;
           if (!findString) {
             this.startFind();
             return;
           }
 
+          // user explicitly requested another search, so do it even if we think it'll fail
+          this._findFailedString = null;
+
           var res;
           // Ensure the stored SearchString is in sync with what we want to find
           if (this._findField.value != this._browser.fastFind.searchString &&
               !this.hidden)
             res = this._find(this._findField.value);
           else
             res = this._findAgain(aFindPrevious);