From 98d2e5fe7336d87ec1dd23225c34947014b2d2e1 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 25 Oct 2024 16:28:08 -0600 Subject: [PATCH] Quote fixes (#19765) Closes #19372 Release Notes: - Fixed autoclosing quotes when the string is already open. - Added autoclosing of rust multiline strings --------- Co-authored-by: Kurt Wolf --- crates/editor/src/editor.rs | 15 +++++++++++++++ crates/languages/src/rust/config.toml | 3 +++ 2 files changed, 18 insertions(+) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 641ccc27151bd9a5a373266f68a3f29281790a04..d23889b42767991c5021edf3ff69f9dd23c66a82 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -3282,10 +3282,25 @@ impl Editor { &bracket_pair.start[..prefix_len], )); + let is_closing_quote = if bracket_pair.end == bracket_pair.start + && bracket_pair.start.len() == 1 + { + let target = bracket_pair.start.chars().next().unwrap(); + let current_line_count = snapshot + .reversed_chars_at(selection.start) + .take_while(|&c| c != '\n') + .filter(|&c| c == target) + .count(); + current_line_count % 2 == 1 + } else { + false + }; + if autoclose && bracket_pair.close && following_text_allows_autoclose && preceding_text_matches_prefix + && !is_closing_quote { let anchor = snapshot.anchor_before(selection.end); new_selections.push((selection.map(|_| anchor), text.len())); diff --git a/crates/languages/src/rust/config.toml b/crates/languages/src/rust/config.toml index d01f62e354ea483c634e16705603acf0c7e644f3..81b9c1e2d94d7f3fc66cbdea3916b30c1dc18488 100644 --- a/crates/languages/src/rust/config.toml +++ b/crates/languages/src/rust/config.toml @@ -5,6 +5,9 @@ line_comments = ["// ", "/// ", "//! "] autoclose_before = ";:.,=}])>" brackets = [ { start = "{", end = "}", close = true, newline = true }, + { start = "r#\"", end = "\"#", close = true, newline = true }, + { start = "r##\"", end = "\"##", close = true, newline = true }, + { start = "r###\"", end = "\"###", close = true, newline = true }, { start = "[", end = "]", close = true, newline = true }, { start = "(", end = ")", close = true, newline = true }, { start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },