From c329780ea7096386e97510414f63c51c3aec8723 Mon Sep 17 00:00:00 2001 From: Zirak Date: Sat, 26 May 2018 21:13:42 +0000 Subject: [PATCH] Editor autocomplete won't insert unnecessary quotes When autocompleting a string (e.g. emit_signal or connect), e.g. emit_signal('visibility_c') ^ where "^" is the cursor, hitting would insert an unnecessary quote, breaking the string: emit_signal('visibility_changed'') This commit adds a small lookahead, so the end result will be as the user probably expected: emit_signal('visibility_changed') --- scene/gui/text_edit.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 55a650ff12..f36c001de3 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -5535,7 +5535,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--; }