diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-02-23 22:13:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-23 22:13:27 +0100 |
commit | 194fd2d5a5c6a7a0e9997759dc2a361450d9dc24 (patch) | |
tree | 3ed38fe6d390319b84de76f05acf541e3d82a8e7 /scene | |
parent | bd76ca01d40b007fec74e945c1f64843882e0f60 (diff) | |
parent | 6a404a88e4ed865eae9ce7c603c64423b92d9621 (diff) |
Merge pull request #36089 from dreamsComeTrue/fix-autocomplete-quotes
Fix: auto brace complete for quoted strings
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/text_edit.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 1c8d7c542b..52cb711bfe 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -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); cursor_set_column(cursor_position_to_move); } |