Skip to content

Truly independent web browser

LibWeb: Move the cursor of a textarea without a text node on value set

Andreas Kling960ff32faa8c
diff --git a/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
index f2e49a73bd6..d6947823c3b 100644
--- a/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
@@ -203,10 +203,12 @@ void HTMLTextAreaElement::set_value(Utf16View value)
if (m_text_node) {
MUST(m_text_node->replace_data(0, m_text_node->length_in_utf16_code_units(), m_raw_value));
update_placeholder_visibility();
-
- set_the_selection_range(m_text_node->length(), m_text_node->length());
}
+ // NB: A textarea without a text node still has a selection, so this also applies to it.
+ auto end_of_text_control = m_text_node ? m_text_node->length() : api_value().length_in_code_units();
+ set_the_selection_range(end_of_text_control, end_of_text_control);
+
CSS::Invalidation::invalidate_style_after_placeholder_shown_change(*this);
}
}
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/textfieldselection/selection-after-content-change.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/textfieldselection/selection-after-content-change.txt
index 7506ddd3cdc..fdab1d2c7f4 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/textfieldselection/selection-after-content-change.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/textfieldselection/selection-after-content-change.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 18 tests
-17 Pass
-1 Fail
+18 Pass
Pass input out of document: selection must not change when setting the same value
Pass input out of document: selection must change when setting a different value
Pass input out of document: selection must not change when setting a value that becomes the same after the value sanitization algorithm
@@ -14,7 +13,7 @@ Pass input in document, with focus: selection must not change when setting the s
Pass input in document, with focus: selection must change when setting a different value
Pass input in document, with focus: selection must not change when setting a value that becomes the same after the value sanitization algorithm
Pass textarea out of document: selection must not change when setting the same value
-Fail textarea out of document: selection must change when setting a different value
+Pass textarea out of document: selection must change when setting a different value
Pass textarea out of document: selection must not change when setting the same normalized value
Pass textarea in document: selection must not change when setting the same value
Pass textarea in document: selection must change when setting a different value