diff --git a/browser/components/search/content/searchbar.js b/browser/components/search/content/searchbar.js index e8b2dd50450c1..d68c293231e11 100644 --- a/browser/components/search/content/searchbar.js +++ b/browser/components/search/content/searchbar.js @@ -451,15 +451,16 @@ /** * Determines if we should select all the text in the searchbar based on the - * searchbar state, and whether the selection is empty. + * clickSelectsAll pref, searchbar state, and whether the selection is empty. */ _maybeSelectAll() { if ( !this._preventClickSelectsAll && + UrlbarPrefs.get("clickSelectsAll") && document.activeElement == this._textbox && this._textbox.selectionStart == this._textbox.selectionEnd ) { - this.select(); + this._textbox.editor.selectAll(); } } @@ -564,6 +565,11 @@ // is text in the textbox. this.openSuggestionsPanel(true); } + + if (event.detail == 2 && UrlbarPrefs.get("doubleClickSelectsAll")) { + this._textbox.editor.selectAll(); + event.preventDefault(); + } }); } diff --git a/browser/components/urlbar/UrlbarInput.sys.mjs b/browser/components/urlbar/UrlbarInput.sys.mjs index 4d2290d52353a..35076b99b3bde 100644 --- a/browser/components/urlbar/UrlbarInput.sys.mjs +++ b/browser/components/urlbar/UrlbarInput.sys.mjs @@ -3166,16 +3166,20 @@ export class UrlbarInput { /** * Determines if we should select all the text in the Urlbar based on the - * Urlbar state, and whether the selection is empty. + * clickSelectsAll pref, Urlbar state, and whether the selection is empty. + * + * @param {boolean} [ignoreClickSelectsAllPref] + * If true, the browser.urlbar.clickSelectsAll pref will be ignored. */ - _maybeSelectAll() { + _maybeSelectAll(ignoreClickSelectsAllPref = false) { if ( !this._preventClickSelectsAll && + (ignoreClickSelectsAllPref || lazy.UrlbarPrefs.get("clickSelectsAll")) && this._compositionState != lazy.UrlbarUtils.COMPOSITION.COMPOSING && this.document.activeElement == this.inputField && this.inputField.selectionStart == this.inputField.selectionEnd ) { - this.select(); + this.editor.selectAll(); } } @@ -3304,7 +3308,9 @@ export class UrlbarInput { return; } - this._maybeSelectAll(); + // If the user right clicks, we select all regardless of the value of + // the browser.urlbar.clickSelectsAll pref. + this._maybeSelectAll(/* ignoreClickSelectsAllPref */ event.button == 2); } _on_focus(event) { @@ -3343,7 +3349,7 @@ export class UrlbarInput { if (this.focusedViaMousedown) { this.view.autoOpen({ event }); } else if (this.inputField.hasAttribute("refocused-by-panel")) { - this._maybeSelectAll(); + this._maybeSelectAll(true); } this._updateUrlTooltip(); @@ -3404,7 +3410,10 @@ export class UrlbarInput { this.inputField.setSelectionRange(0, 0); } - if (event.target.id == SEARCH_BUTTON_ID) { + if (event.detail == 2 && lazy.UrlbarPrefs.get("doubleClickSelectsAll")) { + this.editor.selectAll(); + event.preventDefault(); + } else if (event.target.id == SEARCH_BUTTON_ID) { this._preventClickSelectsAll = true; this.search(lazy.UrlbarTokenizer.RESTRICT.SEARCH); } else { diff --git a/browser/components/urlbar/UrlbarPrefs.sys.mjs b/browser/components/urlbar/UrlbarPrefs.sys.mjs index a8addd7e7982a..31e9a6489cd8d 100644 --- a/browser/components/urlbar/UrlbarPrefs.sys.mjs +++ b/browser/components/urlbar/UrlbarPrefs.sys.mjs @@ -79,6 +79,11 @@ const PREF_URLBAR_DEFAULTS = new Map([ // active view if the the view utilizes OpenSearch. ["contextualSearch.enabled", false], + // If true, this optimizes for replacing the full URL rather than editing + // part of it. This also copies the urlbar value to the selection clipboard + // on systems that support it. + ["clickSelectsAll", false], + // Whether using `ctrl` when hitting return/enter in the URL bar // (or clicking 'go') should prefix 'www.' and suffix // browser.fixup.alternate.suffix to the URL bar value prior to @@ -99,6 +104,11 @@ const PREF_URLBAR_DEFAULTS = new Map([ // but this would mean flushing layout.) ["disableExtendForTests", false], + // If true, this optimizes for replacing the full URL rather than selecting a + // portion of it. This also copies the urlbar value to the selection + // clipboard on systems that support it. + ["doubleClickSelectsAll", false], + // Ensure we use trailing dots for DNS lookups for single words that could // be hosts. ["dnsResolveFullyQualifiedNames", true], diff --git a/browser/components/urlbar/tests/browser/browser_doubleClickSelectsAll.js b/browser/components/urlbar/tests/browser/browser_doubleClickSelectsAll.js new file mode 100644 index 0000000000000..2cd2e7802d619 --- /dev/null +++ b/browser/components/urlbar/tests/browser/browser_doubleClickSelectsAll.js @@ -0,0 +1,45 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + function doubleClick(target) { + let promise = BrowserTestUtils.waitForEvent(target, "dblclick"); + EventUtils.synthesizeMouseAtCenter( + target, + { clickCount: 1 }, + target.ownerGlobal + ); + EventUtils.synthesizeMouseAtCenter( + target, + { clickCount: 2 }, + target.ownerGlobal + ); + return promise; + } + + add_task(async function() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.urlbar.clickSelectsAll", false], + ["browser.urlbar.doubleClickSelectsAll", true], + ], + }); + + let url = "about:mozilla"; + let win = await BrowserTestUtils.openNewBrowserWindow(); + await BrowserTestUtils.openNewForegroundTab({ gBrowser: win.gBrowser, url }); + + await doubleClick(win.gURLBar.inputField); + is( + win.gURLBar.selectionStart, + 0, + "Selection should start at the beginning of the urlbar value" + ); + is( + win.gURLBar.selectionEnd, + url.length, + "Selection should end at the end of the urlbar value" + ); + + win.close(); + }); \ No newline at end of file diff --git a/waterfox/browser/app/profile/00-waterfox.js b/waterfox/browser/app/profile/00-waterfox.js index c9f33a88df9f1..bc9850dea3110 100644 --- a/waterfox/browser/app/profile/00-waterfox.js +++ b/waterfox/browser/app/profile/00-waterfox.js @@ -46,6 +46,16 @@ pref("browser.topsites.contile.enabled", false, locked); pref("browser.topsites.contile.endpoint", "", locked); pref("browser.topsites.useRemoteSetting", false, locked); pref("browser.uiCustomization.state", "{\"placements\":{\"widget-overflow-fixed-list\":[],\"unified-extensions-area\":[],\"nav-bar\":[\"back-button\",\"forward-button\",\"stop-reload-button\",\"urlbar-container\",\"save-to-pocket-button\",\"search-container\",\"downloads-button\",\"fxa-toolbar-menu-button\",\"unified-extensions-button\"],\"TabsToolbar\":[\"firefox-view-button\",\"tabbrowser-tabs\",\"new-tab-button\",\"alltabs-button\"],\"PersonalToolbar\":[\"import-button\",\"personal-bookmarks\"],\"status-bar\":[\"screenshot-button\",\"fullscreen-button\",\"status-text\"]},\"seen\":[\"developer-button\"],\"dirtyAreaCache\":[\"nav-bar\",\"status-bar\",\"PersonalToolbar\",\"TabsToolbar\"],\"currentVersion\":19,\"newElementCount\":3}"); +#ifdef UNIX_BUT_NOT_MAC +pref("browser.urlbar.clickSelectsAll", false); +#else +pref("browser.urlbar.clickSelectsAll", true); +#endif +#ifdef UNIX_BUT_NOT_MAC +pref("browser.urlbar.doubleClickSelectsAll", true); +#else +pref("browser.urlbar.doubleClickSelectsAll", false); +#endif pref("doh-rollout.enabled", false, locked); pref("doh-rollout.disable-heuristics", true, locked); pref("dom.security.unexpected_system_load_telemetry_enabled", false, locked);