mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-19 08:55:26 +00:00
1 parent
328e3738a0
commit
4029e29905
2 files changed
+54
-3
No files matched your search
@@ -198,9 +198,14 @@ fn special(query: &str, o: &Opts) -> (String, bool) {
|
||||
if (o.ignore_punct && is_punct(c)) || (o.ignore_space && is_space(c)) {
|
||||
continue;
|
||||
}
|
||||
// A keyboard apostrophe also finds text produced by smart quotes. Explicit character
|
||||
// codes above, and literal/regex/wildcard searches, keep exact character matching.
|
||||
atoms.push(if c == '\'' { "['‘’]".into() } else { lit(c) });
|
||||
// A keyboard apostrophe or double quote also finds text produced by smart quotes.
|
||||
// Explicit character codes above, and literal/regex/wildcard searches, keep exact
|
||||
// character matching.
|
||||
atoms.push(match c {
|
||||
'\'' => "['‘’]".into(),
|
||||
'"' => "[\"“”]".into(),
|
||||
_ => lit(c),
|
||||
});
|
||||
}
|
||||
let filler = match (o.ignore_punct, o.ignore_space) {
|
||||
(true, true) => r"[\p{P} \t\x{A0}]*",
|
||||
|
||||
@@ -46,3 +46,49 @@ fn normal_apostrophe_search_keeps_exact_modes_and_original_byte_ranges() {
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(text(&s), original);
|
||||
}
|
||||
|
||||
/// A keyboard double quote finds the curly ones smart quotes type, as a keyboard apostrophe does.
|
||||
#[test]
|
||||
fn keyboard_double_quote_finds_smart_quoted_typing() {
|
||||
let mut s = s();
|
||||
for ch in "\"hi\"".chars() {
|
||||
run(&mut s, "text.insert", json!({"text": ch.to_string()}));
|
||||
}
|
||||
assert_eq!(text(&s), "“hi”");
|
||||
for (query, count) in [("\"", 2), ("\"hi", 1), ("hi\"", 1), ("\"hi\"", 1), ("\"HI\"", 1)] {
|
||||
assert_eq!(run(&mut s, "edit.find", json!({"text": query}))["count"], count, "{query}");
|
||||
}
|
||||
assert_eq!(run(&mut s, "edit.find", json!({"text": "\"HI\"", "matchCase": true}))["count"], 0);
|
||||
assert_eq!(run(&mut s, "edit.replaceAll", json!({"text": "\"hi\"", "with": "[^&]"}))["replaced"], 1);
|
||||
assert_eq!(text(&s), "[“hi”]");
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(text(&s), "“hi”");
|
||||
}
|
||||
|
||||
/// Straight and curly double quotes: only a typed `"` in a normal search reads as all three.
|
||||
#[test]
|
||||
fn normal_double_quote_search_keeps_exact_modes_and_original_byte_ranges() {
|
||||
let mut s = s();
|
||||
let original = "🙂 \"hi\" “hi” ”hi“ 'hi' ″hi″";
|
||||
run(&mut s, "document.setText", json!({"text": original}));
|
||||
let found = run(&mut s, "edit.find", json!({"text": "\"hi\""}));
|
||||
assert_eq!(found["count"], 3);
|
||||
let ranges: Vec<_> =
|
||||
found["matches"].as_array().unwrap().iter().map(|m| (m["start"]["off"].as_u64().unwrap(), m["end"]["off"].as_u64().unwrap())).collect();
|
||||
assert_eq!(ranges, [(5, 9), (10, 18), (19, 27)]);
|
||||
assert_eq!(run(&mut s, "edit.find", json!({"text": "\""}))["count"], 6);
|
||||
for options in [json!({"special": false}), json!({"wildcards": true}), json!({"regex": true})] {
|
||||
let mut exact = super::s();
|
||||
run(&mut exact, "document.setText", json!({"text": original}));
|
||||
let mut params = options;
|
||||
params["text"] = json!("\"hi\"");
|
||||
assert_eq!(run(&mut exact, "edit.find", params)["count"], 1);
|
||||
}
|
||||
for query in ["^034hi^034", "^u8220hi^u8221", "“hi”", "”hi“"] {
|
||||
assert_eq!(run(&mut s, "edit.find", json!({"text": query}))["count"], 1, "{query}");
|
||||
}
|
||||
assert_eq!(run(&mut s, "edit.replaceAll", json!({"text": "\"hi\"", "with": "<^&>"}))["replaced"], 3);
|
||||
assert_eq!(text(&s), "🙂 <\"hi\"> <“hi”> <”hi“> 'hi' ″hi″");
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(text(&s), original);
|
||||
}
|
||||
Reference in new issue
Block a user