From b92347c2201832421cd4e986dff6c7824791bc2b Mon Sep 17 00:00:00 2001 From: William Deurwaarder Date: Fri, 3 Sep 2021 00:33:50 +0200 Subject: [PATCH] Fix incorrectly removing two characters by auto brace In some situations when there were no braces auto brace still removed two characters. This has been fixed by adding a test that a brace is found. --- scene/gui/code_edit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 5f3ab18ccad..d1ce0084f01 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -1937,7 +1937,7 @@ void CodeEdit::confirm_code_completion(bool p_replace) { if (pre_brace_pair == -1 && post_brace_pair == -1 && get_caret_column() > 0 && get_caret_column() < get_line(caret_line).length()) { pre_brace_pair = _get_auto_brace_pair_open_at_pos(caret_line, get_caret_column() + 1); - if (pre_brace_pair == _get_auto_brace_pair_close_at_pos(caret_line, get_caret_column() - 1)) { + if (pre_brace_pair != -1 && pre_brace_pair == _get_auto_brace_pair_close_at_pos(caret_line, get_caret_column() - 1)) { remove_text(caret_line, get_caret_column() - 2, caret_line, get_caret_column()); if (_get_auto_brace_pair_close_at_pos(caret_line, get_caret_column() - 1) != pre_brace_pair) { set_caret_column(get_caret_column() - 1);