python: Auto-close f-strings (#28709)
Closes #28707 Release Notes: - Added support for auto-closing `f`, `b`, `u`, `r`, `rb` and the newly released `t` strings in Python
This commit is contained in:
parent
db56254517
commit
26b9c32e96
2 changed files with 22 additions and 4 deletions
|
@ -3169,6 +3169,7 @@ impl Editor {
|
||||||
let mut is_bracket_pair_start = false;
|
let mut is_bracket_pair_start = false;
|
||||||
let mut is_bracket_pair_end = false;
|
let mut is_bracket_pair_end = false;
|
||||||
if !text.is_empty() {
|
if !text.is_empty() {
|
||||||
|
let mut bracket_pair_matching_end = None;
|
||||||
// `text` can be empty when a user is using IME (e.g. Chinese Wubi Simplified)
|
// `text` can be empty when a user is using IME (e.g. Chinese Wubi Simplified)
|
||||||
// and they are removing the character that triggered IME popup.
|
// and they are removing the character that triggered IME popup.
|
||||||
for (pair, enabled) in scope.brackets() {
|
for (pair, enabled) in scope.brackets() {
|
||||||
|
@ -3193,12 +3194,17 @@ impl Editor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pair.end.as_str() == text.as_ref() {
|
if pair.end.as_str() == text.as_ref() && bracket_pair_matching_end.is_none()
|
||||||
bracket_pair = Some(pair.clone());
|
{
|
||||||
is_bracket_pair_end = true;
|
// take first bracket pair matching end, but don't break in case a later bracket
|
||||||
break;
|
// pair matches start
|
||||||
|
bracket_pair_matching_end = Some(pair.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if bracket_pair.is_none() && bracket_pair_matching_end.is_some() {
|
||||||
|
bracket_pair = Some(bracket_pair_matching_end.unwrap());
|
||||||
|
is_bracket_pair_end = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(bracket_pair) = bracket_pair {
|
if let Some(bracket_pair) = bracket_pair {
|
||||||
|
|
|
@ -5,6 +5,18 @@ first_line_pattern = '^#!.*\bpython[0-9.]*\b'
|
||||||
line_comments = ["# "]
|
line_comments = ["# "]
|
||||||
autoclose_before = ";:.,=}])>"
|
autoclose_before = ";:.,=}])>"
|
||||||
brackets = [
|
brackets = [
|
||||||
|
{ start = "f\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "f'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "b\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "b'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "u\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "u'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "r\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "r'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "rb\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "rb'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "t\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "t'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
{ start = "\"\"\"", end = "\"\"\"", close = true, newline = false, not_in = ["string"] },
|
{ start = "\"\"\"", end = "\"\"\"", close = true, newline = false, not_in = ["string"] },
|
||||||
{ start = "'''", end = "'''", close = true, newline = false, not_in = ["string"] },
|
{ start = "'''", end = "'''", close = true, newline = false, not_in = ["string"] },
|
||||||
{ start = "{", end = "}", close = true, newline = true },
|
{ start = "{", end = "}", close = true, newline = true },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue