Skip to content

Commit

Permalink
Allow various clickSelectsAll behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlex94 committed Oct 1, 2023
1 parent 034b2f5 commit e207d88
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 8 deletions.
10 changes: 8 additions & 2 deletions browser/components/search/content/searchbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
});
}

Expand Down
21 changes: 15 additions & 6 deletions browser/components/urlbar/UrlbarInput.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions browser/components/urlbar/UrlbarPrefs.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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],
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
10 changes: 10 additions & 0 deletions waterfox/browser/app/profile/00-waterfox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e207d88

Please sign in to comment.