From 1aac10d73d4f4acb901f2af76fc1c6cc5cb02b75 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Sat, 14 Jan 2023 15:06:44 +0000 Subject: [PATCH] Fixed adding extra quote when completing strings --- scene/gui/code_edit.cpp | 8 +++++--- 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 7539810feb9..4356e91e41d 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 c68560000c5..5447c99a64a 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();