From d0afedfc20fac59e64370d44ceae4be176373d0b Mon Sep 17 00:00:00 2001 From: ldm0 Date: Wed, 2 Sep 2026 01:45:42 +0800 Subject: [PATCH] fix(selectors): resolve clean textarea directionality --- moli-selector/src/lib.rs | 12 +++++++++++- moli-selector/src/stylo/query/pseudo.rs | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/moli-selector/src/lib.rs b/moli-selector/src/lib.rs index 717285c79c..c41e9bf0d0 100644 --- a/moli-selector/src/lib.rs +++ b/moli-selector/src/lib.rs @@ -1703,11 +1703,21 @@ mod tests { let textarea = host.create_element("textarea"); assert!(host.set_attribute(textarea, "dir", "auto")); - assert!(host.set_input_value(textarea, "\u{05ea}")); + let textarea_text = host.create_text_node("\u{05ea}"); + assert!(host.append_child(textarea, textarea_text)); assert!(host.append_child(body, textarea)); assert!(!engine.matches_host(&host, textarea, ":dir(ltr)").unwrap()); assert!(engine.matches_host(&host, textarea, ":dir(rtl)").unwrap()); + assert!(host.set_text_content(textarea, "A")); + assert!(engine.matches_host(&host, textarea, ":dir(ltr)").unwrap()); + assert!(!engine.matches_host(&host, textarea, ":dir(rtl)").unwrap()); + + assert!(host.set_input_value(textarea, "\u{05ea}")); + assert!(host.set_text_content(textarea, "A")); + assert!(!engine.matches_host(&host, textarea, ":dir(ltr)").unwrap()); + assert!(engine.matches_host(&host, textarea, ":dir(rtl)").unwrap()); + assert!(host.set_input_value(textarea, "A")); assert!(engine.matches_host(&host, textarea, ":dir(ltr)").unwrap()); assert!(!engine.matches_host(&host, textarea, ":dir(rtl)").unwrap()); diff --git a/moli-selector/src/stylo/query/pseudo.rs b/moli-selector/src/stylo/query/pseudo.rs index e3e05d2c56..9f21d4b35d 100644 --- a/moli-selector/src/stylo/query/pseudo.rs +++ b/moli-selector/src/stylo/query/pseudo.rs @@ -739,7 +739,12 @@ pub(crate) fn html_auto_directionality_invalidation_root( fn auto_direction_for_element(host: &DomHost, root: NodeId) -> Option { if let Some(element) = host.node(root).and_then(Node::as_element) { if element.is_html_textarea() { - return first_strong_text_direction(&element.input_value()); + let value = if element.input_value_dirty() { + element.input_value() + } else { + host.direct_text_content(root).unwrap_or_default() + }; + return first_strong_text_direction(&value); } if element.is_html_input() { return input_auto_direction(element);