зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1658605 - Enter search mode when a token alias is autofilled. r=harry
Differential Revision: https://phabricator.services.mozilla.com/D88415
This commit is contained in:
Родитель
0d0bffa160
Коммит
ed163ca20b
|
@ -372,10 +372,12 @@ class UrlbarController {
|
|||
}
|
||||
event.preventDefault();
|
||||
break;
|
||||
case KeyEvent.DOM_VK_LEFT:
|
||||
case KeyEvent.DOM_VK_RIGHT:
|
||||
case KeyEvent.DOM_VK_HOME:
|
||||
case KeyEvent.DOM_VK_END:
|
||||
this.input.maybePromoteKeywordToSearchMode();
|
||||
// Fall through.
|
||||
case KeyEvent.DOM_VK_LEFT:
|
||||
case KeyEvent.DOM_VK_HOME:
|
||||
this.view.removeAccessibleFocus();
|
||||
break;
|
||||
case KeyEvent.DOM_VK_BACK_SPACE:
|
||||
|
|
|
@ -1484,6 +1484,21 @@ class UrlbarInput {
|
|||
this._afterTabSelectAndFocusChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Certain actions can autofill a keyword into searchMode
|
||||
* @param {UrlbarResult} [result] The currently selected urlbar result.
|
||||
* @returns {boolean} Whether Search Mode was started.
|
||||
*/
|
||||
maybePromoteKeywordToSearchMode(result = this._resultForCurrentValue) {
|
||||
let searchMode = this._searchModeForResult(result);
|
||||
if (searchMode && this.value.trim() == result.payload.keyword.trim()) {
|
||||
this.setSearchMode(searchMode);
|
||||
this.value = "";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Private methods below.
|
||||
|
||||
_getURIFixupInfo(searchString) {
|
||||
|
@ -2445,13 +2460,7 @@ class UrlbarInput {
|
|||
// offer result.
|
||||
let enteredSearchMode = false;
|
||||
if (event.data == " ") {
|
||||
let result = this.view.selectedResult;
|
||||
let searchMode = this._searchModeForResult(result);
|
||||
if (searchMode && this.value.trim() == result.payload.keyword.trim()) {
|
||||
this.setSearchMode(searchMode);
|
||||
this.value = "";
|
||||
enteredSearchMode = true;
|
||||
}
|
||||
enteredSearchMode = this.maybePromoteKeywordToSearchMode();
|
||||
}
|
||||
|
||||
let value = this.value;
|
||||
|
|
|
@ -461,8 +461,7 @@ add_task(async function enterAutofillsAlias_legacy() {
|
|||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
|
||||
// Pressing enter on an @ alias autofill should fill it in the urlbar input
|
||||
// with a trailing space and move the caret at the end.
|
||||
// Pressing Enter on an @ alias autofill should enter search mode.
|
||||
add_task(async function enterAutofillsAlias() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.urlbar.update2", true]],
|
||||
|
@ -479,7 +478,6 @@ add_task(async function enterAutofillsAlias() {
|
|||
0
|
||||
);
|
||||
|
||||
// Press Enter.
|
||||
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
EventUtils.synthesizeKey("KEY_Enter");
|
||||
await searchPromise;
|
||||
|
@ -496,6 +494,37 @@ add_task(async function enterAutofillsAlias() {
|
|||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
|
||||
// Pressing Right on an @ alias autofill should enter search mode.
|
||||
add_task(async function enterAutofillsAlias() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.urlbar.update2", true]],
|
||||
});
|
||||
for (let value of [ALIAS.substring(0, ALIAS.length - 1), ALIAS]) {
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value,
|
||||
selectionStart: value.length,
|
||||
selectionEnd: value.length,
|
||||
});
|
||||
let testEngineItem = await UrlbarTestUtils.waitForAutocompleteResultAt(
|
||||
window,
|
||||
0
|
||||
);
|
||||
|
||||
EventUtils.synthesizeKey("KEY_ArrowRight");
|
||||
|
||||
await UrlbarTestUtils.assertSearchMode(window, {
|
||||
engineName: testEngineItem.result.payload.engine,
|
||||
});
|
||||
|
||||
gURLBar.setSearchMode({});
|
||||
}
|
||||
await UrlbarTestUtils.promisePopupClose(window, () =>
|
||||
EventUtils.synthesizeKey("KEY_Escape")
|
||||
);
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
|
||||
async function doSimpleTest(revertBetweenSteps) {
|
||||
// When autofill is enabled, searching for "@tes" will autofill to "@test",
|
||||
// which gets in the way of this test task, so temporarily disable it.
|
||||
|
|
Загрузка…
Ссылка в новой задаче