commit 11fd6a9e9ea76c5f000e187303ed6a8342fc1ad9
parent 45bb87a424e6a59804afc42a59b59cb41de306dd
Author: Kagami Sascha Rosylight <krosylight@proton.me>
Date: Wed, 15 Oct 2025 07:57:36 +0000
Bug 1993351 - Set selection as dirty when unbinding from frame r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D268527
Diffstat:
2 files changed, 23 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,17 @@
+<!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>
+<textarea id="t" style="white-space: nowrap">Hello</textarea>
+<script>
+promise_test(async () => {
+ // Home and Delete
+ await test_driver.send_keys(t, ["\uE011", "\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>