commit 69ce430d442444e6492ca81c67d0a5ce289e86c7
parent 12627c518f6f6cd23e271c5a9cb71779190223ac
Author: Daisuke Akatsuka <daisuke@birchill.co.jp>
Date: Wed, 15 Oct 2025 21:49:49 +0000
Bug 1940703: Include actions that exactly match the keyword r=daleharvey
Differential Revision: https://phabricator.services.mozilla.com/D268497
Diffstat:
3 files changed, 46 insertions(+), 30 deletions(-)
diff --git a/browser/components/urlbar/ActionsProviderQuickActions.sys.mjs b/browser/components/urlbar/ActionsProviderQuickActions.sys.mjs
@@ -56,7 +56,7 @@ class ProviderQuickActions extends ActionsProvider {
async queryActions(queryContext) {
let input = queryContext.trimmedLowerCaseSearchString;
- let results = await this.getActions(input);
+ let results = await this.getActions({ input });
if (lazy.UrlbarPrefs.get(MATCH_IN_PHRASE_PREF)) {
for (let [keyword, keys] of this.#keywords) {
@@ -93,9 +93,17 @@ class ProviderQuickActions extends ActionsProvider {
});
}
- async getActions(prefix) {
+ async getActions({ input, includesExactMatch = false }) {
await lazy.QuickActionsLoaderDefault.ensureLoaded();
- return this.#prefixes.get(prefix) ?? new Set();
+
+ let results = this.#prefixes.get(input) ?? new Set();
+
+ if (includesExactMatch) {
+ let actions = this.#keywords.get(input);
+ actions?.forEach(action => results.add(action));
+ }
+
+ return results;
}
getAction(key) {
diff --git a/browser/components/urlbar/UrlbarProviderActionsSearchMode.sys.mjs b/browser/components/urlbar/UrlbarProviderActionsSearchMode.sys.mjs
@@ -41,7 +41,10 @@ export class UrlbarProviderActionsSearchMode extends UrlbarProvider {
async startQuery(queryContext, addCallback) {
let input = queryContext.trimmedLowerCaseSearchString;
- let results = await lazy.ActionsProviderQuickActions.getActions(input);
+ let results = await lazy.ActionsProviderQuickActions.getActions({
+ input,
+ includesExactMatch: true,
+ });
results.forEach(resultKey => {
let result = new lazy.UrlbarResult({
type: UrlbarUtils.RESULT_TYPE.DYNAMIC,
diff --git a/browser/components/urlbar/tests/browser/browser_secondaryActions.js b/browser/components/urlbar/tests/browser/browser_secondaryActions.js
@@ -179,35 +179,40 @@ add_task(async function test_sitesearch() {
});
add_task(async function enter_action_search_mode() {
- await UrlbarTestUtils.promiseAutocompleteResultPopup({
- window,
- value: "> ",
- });
- await UrlbarTestUtils.assertSearchMode(window, {
- source: UrlbarUtils.RESULT_SOURCE.ACTIONS,
- entry: "typed",
- restrictType: "symbol",
- });
- let { result } = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
- Assert.equal(
- result.providerName,
- "UrlbarProviderActionsSearchMode",
- "Actions are shown"
- );
+ // Test with prefix and exact match.
+ const KEYWORDS = ["pref", "preferences"];
- let pageLoaded = BrowserTestUtils.browserLoaded(window);
- EventUtils.synthesizeKey("pref", {}, window);
- EventUtils.synthesizeKey("KEY_Tab");
- EventUtils.synthesizeKey("KEY_Enter");
- await pageLoaded;
+ for (let keyword of KEYWORDS) {
+ await UrlbarTestUtils.promiseAutocompleteResultPopup({
+ window,
+ value: "> ",
+ });
+ await UrlbarTestUtils.assertSearchMode(window, {
+ source: UrlbarUtils.RESULT_SOURCE.ACTIONS,
+ entry: "typed",
+ restrictType: "symbol",
+ });
+ let { result } = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
+ Assert.equal(
+ result.providerName,
+ "UrlbarProviderActionsSearchMode",
+ "Actions are shown"
+ );
- Assert.equal(
- window.gBrowser.selectedBrowser.currentURI.spec,
- "about:preferences",
- "Opened settings page"
- );
+ let pageLoaded = BrowserTestUtils.browserLoaded(window);
+ EventUtils.synthesizeKey(keyword, {}, window);
+ EventUtils.synthesizeKey("KEY_Tab");
+ EventUtils.synthesizeKey("KEY_Enter");
+ await pageLoaded;
+
+ Assert.equal(
+ window.gBrowser.selectedBrowser.currentURI.spec,
+ "about:preferences",
+ "Opened settings page"
+ );
- BrowserTestUtils.removeTab(gBrowser.selectedTab);
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+ }
});
add_task(async function test_opensearch() {