Bug 1515285 - Implement selecting switch-to-tab results by keyboard. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D16023

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dão Gottwald 2019-01-14 16:58:21 +00:00
parent 961eb5b518
commit 0e43f06aef
2 changed files with 25 additions and 1 deletions

View File

@ -214,6 +214,16 @@ class UrlbarInput {
// 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;
@ -268,6 +278,8 @@ class UrlbarInput {
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(

View File

@ -54,6 +54,19 @@ class UrlbarView {
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.
@ -303,7 +316,6 @@ class UrlbarView {
if (result) {
this.input.pickResult(event, result);
}
this.close();
}
_on_overflow(event) {