diff options
author | Zirak <zirakertan@gmail.com> | 2018-05-26 21:13:42 +0000 |
---|---|---|
committer | Zirak <zirakertan@gmail.com> | 2018-05-26 21:13:42 +0000 |
commit | c329780ea7096386e97510414f63c51c3aec8723 (patch) | |
tree | 62f5a22ace1798c96e4fcf672607d8c6bcda0baf /scene/gui | |
parent | 130fd6bcb88d7b297b13c3ed20a715b5ab9cce47 (diff) |
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 <tab> 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')
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 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--; } |