Bug 1485746 - Cursor gets reset to start of address bar on window switch. r=adw

This restores the previous behavior where we set the selection only when setting a new different value

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Bonardo 2018-08-30 09:41:24 +00:00
Родитель f4579b5557
Коммит 12bc352965
5 изменённых файлов: 44 добавлений и 8 удалений

Просмотреть файл

@ -2686,9 +2686,15 @@ function URLBarSetURI(aURI) {
valid = true;
}
let isDifferentValidValue = valid && value != gURLBar.value;
gURLBar.value = value;
gURLBar.valueIsTyped = !valid;
gURLBar.removeAttribute("usertyping");
if (isDifferentValidValue) {
// The selection is enforced only for new values, to avoid overriding the
// cursor position when the user switches windows while typing.
gURLBar.selectionStart = gURLBar.selectionEnd = 0;
}
SetPageProxyState(valid ? "valid" : "invalid");
}

Просмотреть файл

@ -151,7 +151,6 @@ support-files =
run-if = e10s
[browser_urlHighlight.js]
[browser_urlOverflow.js]
skip-if = true # Bug 1482557
[browser_wyciwyg_urlbarCopying.js]
subsuite = clipboard
support-files =

Просмотреть файл

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function() {
add_task(async function test_arrowRight() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
await promiseAutocompleteResultPopup("www.mozilla.org");
await waitForAutocompleteResultAt(0);
@ -19,3 +19,22 @@ add_task(async function() {
BrowserTestUtils.removeTab(tab);
});
add_task(async function test_windowSwitch() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
await promiseAutocompleteResultPopup("www.mozilla.org");
await waitForAutocompleteResultAt(0);
gURLBar.focus();
gURLBar.selectTextRange(4, 4);
let newWindow = await BrowserTestUtils.openNewBrowserWindow();
await BrowserTestUtils.closeWindow(newWindow);
Assert.equal(document.activeElement, gURLBar.inputField, "URL Bar should be focused");
is(gURLBar.selectionStart, 4, "Should not have moved the cursor");
is(gURLBar.selectionEnd, 4, "Should not have selected anything");
BrowserTestUtils.removeTab(tab);
});

Просмотреть файл

@ -4,9 +4,13 @@
async function testVal(aExpected, overflowSide = "") {
info(`Testing ${aExpected}`);
gURLBar.value = aExpected;
URLBarSetURI(makeURI(aExpected));
Assert.equal(gURLBar.selectionStart, gURLBar.selectionEnd,
"Selection sanity check");
gURLBar.focus();
Assert.equal(document.activeElement, gURLBar.inputField, "URL Bar should be focused");
Assert.equal(gURLBar.scheme.value, "", "Check the scheme value");
Assert.equal(getComputedStyle(gURLBar.scheme).visibility, "hidden",
"Check the scheme box visibility");
@ -22,8 +26,6 @@ async function testVal(aExpected, overflowSide = "") {
if (scheme == "http://" && Services.prefs.getBoolPref("browser.urlbar.trimURLs", true))
scheme = "";
Assert.equal(gURLBar.selectionStart, gURLBar.selectionEnd,
"Selection sanity check");
Assert.equal(gURLBar.scheme.value, scheme, "Check the scheme value");
let isOverflowed = gURLBar.inputField.scrollWidth > gURLBar.inputField.clientWidth;
Assert.equal(isOverflowed, !!overflowSide, "Check The input field overflow");
@ -39,8 +41,13 @@ async function testVal(aExpected, overflowSide = "") {
}
add_task(async function() {
// We use a new tab for the test to be sure all the tab switching and loading
// is complete before starting, otherwise onLocationChange for this tab could
// override the value we set with an empty value.
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
registerCleanupFunction(function() {
URLBarSetURI();
BrowserTestUtils.removeTab(tab);
});
let lotsOfSpaces = new Array(200).fill("%20").join("");

Просмотреть файл

@ -598,9 +598,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
}
// Make sure the host is always visible. Since it is aligned on
// the first strong directional character, we set the overflow
// appropriately.
this.selectionStart = this.selectionEnd = 0;
// the first strong directional character, we set scrollLeft
// appropriately to ensure the domain stays visible in case of an
// overflow.
window.requestAnimationFrame(() => {
// Check for re-entrance. On focus change this formatting code is
// invoked regardless, thus this should be enough.
@ -980,6 +980,11 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
this.handleRevert();
}
}
if (openUILinkWhere == "current") {
// Ensure the start of the URL is visible for usability reasons.
this.selectionStart = this.selectionEnd = 0;
}
]]></body>
</method>