diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2023-01-15 00:11:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-15 00:11:42 +0100 |
commit | 03d11e608e978f299b4e7061fbe7bf126d26b667 (patch) | |
tree | f3efa31f3393fddeb858d0034fff14b05668c355 | |
parent | 60d031777b2a922cba03210181c9ba7ad3a6f3ab (diff) | |
parent | 1aac10d73d4f4acb901f2af76fc1c6cc5cb02b75 (diff) |
Merge pull request #71402 from Paulb23/autocomplete-extra-quote
Fixed adding extra quote when completing strings
-rw-r--r-- | scene/gui/code_edit.cpp | 8 | ||||
-rw-r--r-- | tests/scene/test_code_edit.h | 2 |
2 files changed, 6 insertions, 4 deletions
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 7539810feb..4356e91e41 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -2086,9 +2086,11 @@ void CodeEdit::confirm_code_completion(bool p_replace) { int post_brace_pair = get_caret_column(i) < get_line(caret_line).length() ? _get_auto_brace_pair_close_at_pos(caret_line, get_caret_column(i)) : -1; // Strings do not nest like brackets, so ensure we don't add an additional closing pair. - if (has_string_delimiter(String::chr(last_completion_char)) && post_brace_pair != -1 && last_char_matches) { - remove_text(caret_line, get_caret_column(i), caret_line, get_caret_column(i) + 1); - adjust_carets_after_edit(i, caret_line, get_caret_column(i), caret_line, get_caret_column(i) + 1); + if (has_string_delimiter(String::chr(last_completion_char))) { + if (post_brace_pair != -1 && last_char_matches) { + remove_text(caret_line, get_caret_column(i), caret_line, get_caret_column(i) + 1); + adjust_carets_after_edit(i, caret_line, get_caret_column(i), caret_line, get_caret_column(i) + 1); + } } else { if (pre_brace_pair != -1 && pre_brace_pair != post_brace_pair && last_char_matches) { remove_text(caret_line, get_caret_column(i), caret_line, get_caret_column(i) + 1); diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h index c68560000c..5447c99a64 100644 --- a/tests/scene/test_code_edit.h +++ b/tests/scene/test_code_edit.h @@ -2930,7 +2930,7 @@ TEST_CASE("[SceneTree][CodeEdit] completion") { code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_NODE_PATH, "\"test", "\"test"); code_edit->update_code_completion_options(); code_edit->confirm_code_completion(); - CHECK(code_edit->get_line(0) == "\"\"test\"\""); + CHECK(code_edit->get_line(0) == "\"\"test\""); CHECK(code_edit->get_caret_column() == 7); code_edit->undo(); |