Fix quotes in Rust (#19914)
Release Notes: - (preview only) Fixed quote-autoclose in Rust
This commit is contained in:
parent
6ea4662326
commit
fc5cde9434
2 changed files with 18 additions and 18 deletions
|
@ -3244,9 +3244,21 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if enabled && pair.start.ends_with(text.as_ref()) {
|
if enabled && pair.start.ends_with(text.as_ref()) {
|
||||||
bracket_pair = Some(pair.clone());
|
let prefix_len = pair.start.len() - text.len();
|
||||||
is_bracket_pair_start = true;
|
let preceding_text_matches_prefix = prefix_len == 0
|
||||||
break;
|
|| (selection.start.column >= (prefix_len as u32)
|
||||||
|
&& snapshot.contains_str_at(
|
||||||
|
Point::new(
|
||||||
|
selection.start.row,
|
||||||
|
selection.start.column - (prefix_len as u32),
|
||||||
|
),
|
||||||
|
&pair.start[..prefix_len],
|
||||||
|
));
|
||||||
|
if preceding_text_matches_prefix {
|
||||||
|
bracket_pair = Some(pair.clone());
|
||||||
|
is_bracket_pair_start = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if pair.end.as_str() == text.as_ref() {
|
if pair.end.as_str() == text.as_ref() {
|
||||||
bracket_pair = Some(pair.clone());
|
bracket_pair = Some(pair.clone());
|
||||||
|
@ -3263,8 +3275,6 @@ impl Editor {
|
||||||
self.use_auto_surround && snapshot_settings.use_auto_surround;
|
self.use_auto_surround && snapshot_settings.use_auto_surround;
|
||||||
if selection.is_empty() {
|
if selection.is_empty() {
|
||||||
if is_bracket_pair_start {
|
if is_bracket_pair_start {
|
||||||
let prefix_len = bracket_pair.start.len() - text.len();
|
|
||||||
|
|
||||||
// If the inserted text is a suffix of an opening bracket and the
|
// If the inserted text is a suffix of an opening bracket and the
|
||||||
// selection is preceded by the rest of the opening bracket, then
|
// selection is preceded by the rest of the opening bracket, then
|
||||||
// insert the closing bracket.
|
// insert the closing bracket.
|
||||||
|
@ -3272,15 +3282,6 @@ impl Editor {
|
||||||
.chars_at(selection.start)
|
.chars_at(selection.start)
|
||||||
.next()
|
.next()
|
||||||
.map_or(true, |c| scope.should_autoclose_before(c));
|
.map_or(true, |c| scope.should_autoclose_before(c));
|
||||||
let preceding_text_matches_prefix = prefix_len == 0
|
|
||||||
|| (selection.start.column >= (prefix_len as u32)
|
|
||||||
&& snapshot.contains_str_at(
|
|
||||||
Point::new(
|
|
||||||
selection.start.row,
|
|
||||||
selection.start.column - (prefix_len as u32),
|
|
||||||
),
|
|
||||||
&bracket_pair.start[..prefix_len],
|
|
||||||
));
|
|
||||||
|
|
||||||
let is_closing_quote = if bracket_pair.end == bracket_pair.start
|
let is_closing_quote = if bracket_pair.end == bracket_pair.start
|
||||||
&& bracket_pair.start.len() == 1
|
&& bracket_pair.start.len() == 1
|
||||||
|
@ -3299,7 +3300,6 @@ impl Editor {
|
||||||
if autoclose
|
if autoclose
|
||||||
&& bracket_pair.close
|
&& bracket_pair.close
|
||||||
&& following_text_allows_autoclose
|
&& following_text_allows_autoclose
|
||||||
&& preceding_text_matches_prefix
|
|
||||||
&& !is_closing_quote
|
&& !is_closing_quote
|
||||||
{
|
{
|
||||||
let anchor = snapshot.anchor_before(selection.end);
|
let anchor = snapshot.anchor_before(selection.end);
|
||||||
|
|
|
@ -5,9 +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, not_in = ["string", "comment"] },
|
||||||
{ start = "r##\"", end = "\"##", close = true, newline = true },
|
{ start = "r##\"", end = "\"##", close = true, newline = true, not_in = ["string", "comment"] },
|
||||||
{ start = "r###\"", end = "\"###", close = true, newline = true },
|
{ start = "r###\"", end = "\"###", close = true, newline = true, not_in = ["string", "comment"] },
|
||||||
{ 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