Bug 1515285 - Implement selecting switch-to-tab results by keyboard. r=Standard8
authorDão Gottwald <dao@mozilla.com>
Mon, 14 Jan 2019 16:58:21 +0000
changeset 510863 944a2fbd7454ba098144293f95f5fe6011339073
parent 510862 8844751cb1698c69c2fead027fb31e791bc0ab00
child 510864 dad40f23f4c19891cbd7e6f805bf1eda699d7b16
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1515285
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1515285 - Implement selecting switch-to-tab results by keyboard. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D16023
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/UrlbarView.jsm
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -209,16 +209,26 @@ class UrlbarInput {
     // }
     //
     // // Do the command of the selected one-off if it's not an engine.
     // if (selectedOneOff && !selectedOneOff.engine) {
     //   selectedOneOff.doCommand();
     //   return;
     // }
 
+    // Use the selected result if we have one; this should always be the case
+    // when the view is open.
+    let result = this.view.selectedResult;
+    if (result) {
+      this.pickResult(event, result);
+      return;
+    }
+
+    // Use the current value if we don't have a UrlbarMatch e.g. because the
+    // view is closed.
     let url = this.value;
     if (!url) {
       return;
     }
 
     let where = openWhere || this._whereToOpen(event);
 
     openParams.postData = null;
@@ -263,16 +273,18 @@ class UrlbarInput {
    * Called by the view when a result is picked.
    *
    * @param {Event} event The event that picked the result.
    * @param {UrlbarMatch} result The result that was picked.
    */
   pickResult(event, result) {
     this.setValueFromResult(result);
 
+    this.view.close();
+
     // TODO: Work out how we get the user selection behavior, probably via passing
     // it in, since we don't have the old autocomplete controller to work with.
     // BrowserUsageTelemetry.recordUrlbarSelectedResultMethod(
     //   event, this.userSelectionBehavior);
 
     let where = this._whereToOpen(event);
     let openParams = {
       postData: null,
--- a/browser/components/urlbar/UrlbarView.jsm
+++ b/browser/components/urlbar/UrlbarView.jsm
@@ -50,16 +50,29 @@ class UrlbarView {
    * @returns {boolean}
    *   Whether the panel is open.
    */
   get isOpen() {
     return this.panel.state == "open" || this.panel.state == "showing";
   }
 
   /**
+   * @returns {UrlbarMatch}
+   *   The currently selected result.
+   */
+  get selectedResult() {
+    if (!this.isOpen) {
+      return null;
+    }
+
+    let resultIndex = this._selected.getAttribute("resultIndex");
+    return this._queryContext.results[resultIndex];
+  }
+
+  /**
    * Selects the next or previous view item. An item could be an autocomplete
    * result or a one-off search button.
    *
    * @param {boolean} options.reverse
    *   Set to true to select the previous item. By default the next item
    *   will be selected.
    */
   selectNextItem({reverse = false} = {}) {
@@ -298,17 +311,16 @@ class UrlbarView {
     while (!row.classList.contains("urlbarView-row")) {
       row = row.parentNode;
     }
     let resultIndex = row.getAttribute("resultIndex");
     let result = this._queryContext.results[resultIndex];
     if (result) {
       this.input.pickResult(event, result);
     }
-    this.close();
   }
 
   _on_overflow(event) {
     if (event.target.classList.contains("urlbarView-row-inner")) {
       event.target.toggleAttribute("overflow", true);
     }
   }