fix(selectors): resolve clean textarea directionality

This commit is contained in:
ldm0
2026-09-23 00:11:53 +08:00
parent f77bf8dcae
commit d0afedfc20
2 changed files with 17 additions and 2 deletions
+11 -1
View File
@@ -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());
+6 -1
View File
@@ -739,7 +739,12 @@ pub(crate) fn html_auto_directionality_invalidation_root(
fn auto_direction_for_element(host: &DomHost, root: NodeId) -> Option<CssDirection> {
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);