Bug 781617 - autoFill should respect user's input.
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 21 Sep 2012 16:56:20 +0200
changeset 26426 a6f6319da32967e7e70da6a1e5d58319007840db
parent 26425 f28b5da7112d57fb3aafa60d99757545cfd10a04
child 26427 fbd0445e2fbb8634d94d4e28dc1721635c392b7d
push id1834
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:48:40 +0000
treeherdercomm-beta@293cffe83e59 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs781617
Bug 781617 - autoFill should respect user's input. r=unfocused
suite/common/places/nsPlacesAutoComplete.js
--- a/suite/common/places/nsPlacesAutoComplete.js
+++ b/suite/common/places/nsPlacesAutoComplete.js
@@ -1398,16 +1398,23 @@ urlInlineComplete.prototype = {
           untrimmedDomain = query.getString(1);
         }
       } finally {
         query.reset();
       }
 
       if (hasDomainResult) {
         // We got a match for a domain, we can add it immediately.
+        // If the untrimmed value doesn't preserve the user's input just
+        // ignore it and complete to the found domain.
+        if (untrimmedDomain &&
+            !untrimmedDomain.toLowerCase().contains(this._originalSearchString.toLowerCase())) {
+          untrimmedDomain = null;
+        }
+
         // TODO (bug 754265): this is a temporary solution introduced while
         // waiting for a propert dedicated API.
         result.appendMatch(this._strippedPrefix + domain, untrimmedDomain);
 
         this._finishSearch();
         return;
       }
     }
@@ -1508,19 +1515,27 @@ urlInlineComplete.prototype = {
       separatorIndex += this._currentSearchString.length;
       if (url[separatorIndex] == "/") {
         separatorIndex++; // Include the "/" separator
       }
       url = url.slice(0, separatorIndex);
     }
 
     // Add the result.
+    // If the untrimmed value doesn't preserve the user's input just
+    // ignore it and complete to the found url.
+    let untrimmedURL = prefix + url;
+    if (untrimmedURL &&
+        !untrimmedURL.toLowerCase().contains(this._originalSearchString.toLowerCase())) {
+      untrimmedURL = null;
+     }
+
     // TODO (bug 754265): this is a temporary solution introduced while
     // waiting for a propert dedicated API.
-    this._result.appendMatch(this._strippedPrefix + url, prefix + url);
+    this._result.appendMatch(this._strippedPrefix + url, untrimmedURL);
 
     // handleCompletion() will cause the result listener to be called, and
     // will display the result in the UI.
   },
 
   handleError: function UIC_handleError(aError)
   {
     Components.utils.reportError("URL Inline Complete: An async statement encountered an " +