summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorDominik 'dreamsComeTrue' Jasiński <dominikjasinski@o2.pl>2020-02-10 23:09:07 +0100
committerDominik 'dreamsComeTrue' Jasiński <dominikjasinski@o2.pl>2020-02-21 23:01:13 +0100
commit6a404a88e4ed865eae9ce7c603c64423b92d9621 (patch)
tree8f8db94ad23c0ae948ce35aa32c2a74231bb6afb /scene
parent78074fed8dc38e74b9fe2962e8c015d1a1f9ae48 (diff)
Fix: auto brace complete for quoted strings
Fixes #36002
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/text_edit.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 9d5e004ed3..e9856c85de 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);
}