Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(selectors): resolve textarea direction from its current value
ldm0e79c5b645110
diff --git a/moli-selector/src/lib.rs b/moli-selector/src/lib.rsindex ad4b83565..a7c1155c4 100644--- a/moli-selector/src/lib.rs+++ b/moli-selector/src/lib.rs@@ -1460,6 +1460,36 @@ mod tests {assert!(engine.matches_host(&host, parent, ":dir(rtl)").unwrap());}+ #[test]+ fn dom_api_selectors_dir_auto_tracks_clean_and_dirty_textarea_values() {+ let url = url::Url::parse("https://example.test/").unwrap();+ let mut host = DomHost::from_dom(NativeDom::new_html(url));+ host.reset_html_document_shell();+ let body = host.document_body_handle().unwrap();+ let engine = QueryEngine;+ let textarea = host.create_element("textarea");+ assert!(host.set_attribute(textarea, "dir", "auto"));+ let text = host.create_text_node("\u{05ea}");+ assert!(host.append_child(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!(host.set_text_content(textarea, "\u{05ea}"));+ assert!(engine.matches_host(&host, textarea, ":dir(ltr)").unwrap());+ assert!(!engine.matches_host(&host, textarea, ":dir(rtl)").unwrap());+ }+#[test]fn dom_api_selectors_dir_on_input_uses_html_directionality_rules() {let url = url::Url::parse("https://example.test/").unwrap();diff --git a/moli-selector/src/stylo/query/pseudo.rs b/moli-selector/src/stylo/query/pseudo.rsindex a63649686..9a1d980b1 100644--- a/moli-selector/src/stylo/query/pseudo.rs+++ b/moli-selector/src/stylo/query/pseudo.rs@@ -618,10 +618,18 @@ pub(crate) fn html_directionality(host: &DomHost, handle: NodeId) -> CssDirectio}fn auto_direction_for_element(host: &DomHost, root: NodeId) -> Option<CssDirection> {- if let Some(element) = host.node(root).and_then(Node::as_element)- && element.is_html_input()- {- return input_auto_direction(element);+ if let Some(element) = host.node(root).and_then(Node::as_element) {+ if element.is_html_textarea() {+ 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);+ }}let mut stack = host.child_handles(root).collect::<Vec<_>>();