From 4029e29905603125dfac92da8f98985b6a600cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A2n=20Minh=20Ngh=C4=A9a?= Date: Tue, 17 Nov 2026 17:38:25 +0700 Subject: [PATCH] #6503: a straight " in Find also finds curly double quotes (#6507) --- crates/engine/src/cmd/find_pattern.rs | 11 +++-- crates/engine/src/tests/find_apostrophes.rs | 46 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/find_pattern.rs b/crates/engine/src/cmd/find_pattern.rs index 104b3d3e91..7ce4815cdc 100644 --- a/crates/engine/src/cmd/find_pattern.rs +++ b/crates/engine/src/cmd/find_pattern.rs @@ -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}]*", diff --git a/crates/engine/src/tests/find_apostrophes.rs b/crates/engine/src/tests/find_apostrophes.rs index c06bb381fe..41e0f3cb16 100644 --- a/crates/engine/src/tests/find_apostrophes.rs +++ b/crates/engine/src/tests/find_apostrophes.rs @@ -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); +}