diff options
author | Max Hilbrunner <mhilbrunner@users.noreply.github.com> | 2018-07-05 02:33:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-05 02:33:33 +0200 |
commit | e3c8ac43c61b19a44f6ee9a6b88d4187fb873a2c (patch) | |
tree | 74f7e970ab12f0cfa72ba3fd0a24b39d1df2d9fd /scene/gui | |
parent | edc63a2f6037e2fa695915094cf2762a5d15953f (diff) | |
parent | c329780ea7096386e97510414f63c51c3aec8723 (diff) |
Merge pull request #19187 from Zirak/editor-autocomplete-quote
Editor autocomplete won't insert unnecessary quotes
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/text_edit.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 5a2563abef..fb3b6f1ba0 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -5590,7 +5590,17 @@ void TextEdit::_confirm_completion() { cursor_set_column(cursor.column - completion_base.length(), false); insert_text_at_cursor(completion_current); - if (completion_current.ends_with("(") && auto_brace_completion_enabled) { + // When inserted into the middle of an existing string, don't add an unnecessary quote + String line = text[cursor.line]; + CharType next_char = line[cursor.column]; + CharType last_completion_char = completion_current[completion_current.length() - 1]; + + if ((last_completion_char == '"' || last_completion_char == '\'') && + last_completion_char == next_char) { + _base_remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1); + } + + if (last_completion_char == '(' && auto_brace_completion_enabled) { insert_text_at_cursor(")"); cursor.column--; } |