diff --git a/src/cloudbox.rs b/src/cloudbox.rs index deaea75..a1f6ec5 100644 --- a/src/cloudbox.rs +++ b/src/cloudbox.rs @@ -1782,11 +1782,12 @@ pub fn box_script(name: &str, v: &Value, scale: (f64, f64)) -> Result<(String, S } None => String::new(), }; + let one_line = by_number(v).and_then(|r| r.ok()).is_some_and(|(_, what)| replaces_field(&what, v)); if !text.is_empty() { - script.push_str(&format!(" && {}", type_script(&text))); + script.push_str(&format!(" && {}", type_script_as(&text, one_line))); } if submit { - script.push_str(" && sleep 0.06 && xdotool key --clearmodifiers Return"); + script.push_str(&format!(" && sleep {} && xdotool key --clearmodifiers Return", if one_line { "0.2" } else { "0.06" })); } let script = script.trim_start_matches(" && ").to_string(); (script, format!("已打字({} 個字){field}{}。", text.chars().count(), if submit { ",再按了 return" } else { "" })) @@ -1829,8 +1830,16 @@ pub fn replaces_field(what: &str, v: &Value) -> bool { } fn type_script(text: &str) -> String { + type_script_as(text, false) +} + +/// `paste`: put the text in at once (clipboard) even when it is short and plain. Into a one-line +/// field that is how it arrives whole: typed key by key into Chromium's address bar right after +/// it opened, the page load and the autocomplete took turns with the keys and the address came +/// out mangled (colons gone, the old text mixed in). +fn type_script_as(text: &str, paste: bool) -> String { let q = crate::tools::sh_quote(text); - if text.is_ascii() && text.chars().count() <= TYPE_KEYS_MAX_CHARS { + if !paste && text.is_ascii() && text.chars().count() <= TYPE_KEYS_MAX_CHARS { return format!("xdotool type --clearmodifiers --delay {TYPE_DELAY_MS} -- {q}"); } format!("printf '%s' {q} > /tmp/anybot-paste.txt && for s in clipboard primary; do setsid xclip -selection $s -i /tmp/anybot-paste.txt /dev/null 2>&1 & done; sleep 0.15; \