Merge pull request #36089 from dreamsComeTrue/fix-autocomplete-quotes

Fix: auto brace complete for quoted strings
This commit is contained in:
Rémi Verschelde 2020-02-23 22:13:27 +01:00 committed by GitHub
commit 194fd2d5a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1844,6 +1844,42 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
} }
} }
String line = text[cursor.line];
bool in_single_quote = false;
bool in_double_quote = false;
int c = 0;
while (c < line.length()) {
if (line[c] == '\\') {
c++; // Skip quoted anything.
if (cursor.column == c) {
break;
}
} else {
if (line[c] == '\'' && !in_double_quote) {
in_single_quote = !in_single_quote;
} else if (line[c] == '"' && !in_single_quote) {
in_double_quote = !in_double_quote;
}
}
c++;
if (cursor.column == c) {
break;
}
}
// Disallow inserting duplicated quotes while already in string
if ((in_single_quote || in_double_quote) && (ch == '"' || ch == '\'')) {
insert_text_at_cursor(ch_single);
cursor_set_column(cursor_position_to_move);
return;
}
insert_text_at_cursor(ch_pair); insert_text_at_cursor(ch_pair);
cursor_set_column(cursor_position_to_move); cursor_set_column(cursor_position_to_move);
} }