Bug 926033 - Correct searchString persistence for different searches in findbar. r=mikedeboer, a=bajaj
authorTom Schuster <evilpies@gmail.com>
Fri, 08 Nov 2013 18:35:28 +0100
changeset 166504 bb81b44bf0d8e698875072ec9e4dba516ad78cdd
parent 166503 818be0367b1db7019f99cf46d72554994a1d5c47
child 166505 51d2d426632146032eb7c2d14ef058004bb6bbee
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer, bajaj
bugs926033
milestone27.0a2
Bug 926033 - Correct searchString persistence for different searches in findbar. r=mikedeboer, a=bajaj
toolkit/content/widgets/findbar.xml
toolkit/modules/Finder.jsm
--- a/toolkit/content/widgets/findbar.xml
+++ b/toolkit/content/widgets/findbar.xml
@@ -858,17 +858,17 @@
 
           // We have to carry around an explicit version of this,
           // because finder.searchString doesn't update on failed
           // searches.
           this.browser._lastSearchString = val;
 
           // 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 ||
+          if (!this._findFailedString ||
               !val.startsWith(this._findFailedString))
           {
             this._enableFindButtons(val);
             if (this.getElement("highlight").checked)
               this._setHighlightTimeout();
 
             this._updateCaseSensitivity(val);
 
--- a/toolkit/modules/Finder.jsm
+++ b/toolkit/modules/Finder.jsm
@@ -30,17 +30,18 @@ Finder.prototype = {
     if (this._listeners.indexOf(aListener) === -1)
       this._listeners.push(aListener);
   },
 
   removeResultListener: function (aListener) {
     this._listeners = this._listeners.filter(l => l != aListener);
   },
 
-  _notify: function (aResult, aFindBackwards, aDrawOutline) {
+  _notify: function (aSearchString, aResult, aFindBackwards, aDrawOutline) {
+    this._searchString = aSearchString;
     this._outlineLink(aDrawOutline);
 
     let foundLink = this._fastFind.foundLink;
     let linkURL = null;
     if (foundLink) {
       let docCharset = null;
       let ownerDoc = foundLink.ownerDocument;
       if (ownerDoc)
@@ -55,56 +56,58 @@ Finder.prototype = {
     }
 
     for (let l of this._listeners) {
       l.onFindResult(aResult, aFindBackwards, linkURL);
     }
   },
 
   get searchString() {
-    return this._fastFind.searchString;
+    return this._searchString;
   },
 
   set caseSensitive(aSensitive) {
     this._fastFind.caseSensitive = aSensitive;
   },
 
   /**
    * Used for normal search operations, highlights the first match.
    *
    * @param aSearchString String to search for.
    * @param aLinksOnly Only consider nodes that are links for the search.
    * @param aDrawOutline Puts an outline around matched links.
    */
   fastFind: function (aSearchString, aLinksOnly, aDrawOutline) {
     let result = this._fastFind.find(aSearchString, aLinksOnly);
-    this._notify(result, false, aDrawOutline);
+    let searchString = this._fastFind.searchString;
+    this._notify(searchString, result, false, aDrawOutline);
   },
 
   /**
    * Repeat the previous search. Should only be called after a previous
    * call to Finder.fastFind.
    *
    * @param aFindBackwards Controls the search direction:
    *    true: before current match, false: after current match.
    * @param aLinksOnly Only consider nodes that are links for the search.
    * @param aDrawOutline Puts an outline around matched links.
    */
   findAgain: function (aFindBackwards, aLinksOnly, aDrawOutline) {
     let result = this._fastFind.findAgain(aFindBackwards, aLinksOnly);
-    this._notify(result, aFindBackwards, aDrawOutline);
+    let searchString = this._fastFind.searchString;
+    this._notify(searchString, result, aFindBackwards, aDrawOutline);
   },
 
   highlight: function (aHighlight, aWord) {
-    this._searchString = aWord;
     let found = this._highlight(aHighlight, aWord, null);
-    if (found)
-      this._notify(Ci.nsITypeAheadFind.FIND_FOUND, false, false);
-    else
-      this._notify(Ci.nsITypeAheadFind.FIND_NOTFOUND, false, false);
+    if (aHighlight) {
+      let result = found ? Ci.nsITypeAheadFind.FIND_FOUND
+                         : Ci.nsITypeAheadFind.FIND_NOTFOUND;
+      this._notify(aWord, result, false, false);
+    }
   },
 
   enableSelection: function() {
     this._fastFind.setSelectionModeAndRepaint(Ci.nsISelectionController.SELECTION_ON);
   },
 
   removeSelection: function() {
     let fastFind = this._fastFind;
@@ -278,17 +281,17 @@ Finder.prototype = {
                                   .getSelection(Ci.nsISelectionController.SELECTION_FIND);
             sel.removeAllRanges();
             // We don't need to listen to this editor any more
             this._unhookListenersAtIndex(x);
           }
         }
       }
 
-      //Removing the highlighting always succeeds, so return true.
+      // Removing the highlighting always succeeds, so return true.
       found = true;
     }
 
     return found;
   },
 
   _highlightRange: function(aRange, aController) {
     let node = aRange.startContainer;