tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit dfa52bf95cd9a851946ac1a89b47d0a4aba5e439
parent ec78446178daf087581889fb5d8e40a84bbdec98
Author: Kagami Sascha Rosylight <krosylight@proton.me>
Date:   Thu, 16 Oct 2025 17:25:43 +0000

Bug 1993351 - Set selection as dirty when unbinding from frame r=masayuki

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

Diffstat:
Mdom/html/TextControlState.cpp | 6++++++
Atesting/web-platform/tests/html/semantics/forms/the-textarea-element/selection-after-whitespace-change.html | 31+++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/dom/html/TextControlState.cpp b/dom/html/TextControlState.cpp @@ -2441,6 +2441,12 @@ void TextControlState::UnbindFromFrame(nsTextControlFrame* aFrame) { DebugOnly<bool> ok = SetValue(value, ValueSetterOption::ByInternalAPI); // TODO Find something better to do if this fails... NS_WARNING_ASSERTION(ok, "SetValue() couldn't allocate memory"); + // And mark the selection as dirty to make sure the selection will be + // restored properly in RestoreSelectionState. See bug 1993351. + if (IsSelectionCached()) { + SelectionProperties& props = GetSelectionProperties(); + props.SetIsDirty(); + } } } diff --git a/testing/web-platform/tests/html/semantics/forms/the-textarea-element/selection-after-whitespace-change.html b/testing/web-platform/tests/html/semantics/forms/the-textarea-element/selection-after-whitespace-change.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<script src="/resources/testdriver-actions.js"></script> +<textarea id="t" style="white-space: nowrap">Hello</textarea> +<script> +promise_test(async () => { + t.focus(); + if (navigator.userAgent.includes("Mac")) { + // Meta+ArrowLeft + await new test_driver.Actions() + .keyDown("\uE03D") + .keyDown("\uE058") + .keyUp("\uE058") + .keyUp("\uE03D") + .send(); + } else { + // Home + await test_driver.send_keys(t, ["\uE011"]); + } + // And then Delete + await test_driver.send_keys(t, ["\uE017"]); + t.style.whiteSpace = "pre-line"; + await new Promise(setTimeout); + assert_equals(t.selectionStart, 0, "selectionStart should remain 0"); + assert_equals(t.selectionEnd, 0, "selectionEnd should remain 0"); +}, "Changing white-space should not change selection"); +</script>