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 <kurtwolfbuilds@gmail.com>
This commit is contained in:
parent
4325819075
commit
98d2e5fe73
2 changed files with 18 additions and 0 deletions
|
@ -3282,10 +3282,25 @@ impl Editor {
|
||||||
&bracket_pair.start[..prefix_len],
|
&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
|
if autoclose
|
||||||
&& bracket_pair.close
|
&& bracket_pair.close
|
||||||
&& following_text_allows_autoclose
|
&& following_text_allows_autoclose
|
||||||
&& preceding_text_matches_prefix
|
&& preceding_text_matches_prefix
|
||||||
|
&& !is_closing_quote
|
||||||
{
|
{
|
||||||
let anchor = snapshot.anchor_before(selection.end);
|
let anchor = snapshot.anchor_before(selection.end);
|
||||||
new_selections.push((selection.map(|_| anchor), text.len()));
|
new_selections.push((selection.map(|_| anchor), text.len()));
|
||||||
|
|
|
@ -5,6 +5,9 @@ line_comments = ["// ", "/// ", "//! "]
|
||||||
autoclose_before = ";:.,=}])>"
|
autoclose_before = ";:.,=}])>"
|
||||||
brackets = [
|
brackets = [
|
||||||
{ start = "{", end = "}", close = true, newline = true },
|
{ 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 = true, newline = true },
|
{ start = "(", end = ")", close = true, newline = true },
|
||||||
{ start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },
|
{ start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue