From 1c50f8660a8931488cc78f1721ee45aec04e3a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Wed, 27 Aug 2025 13:13:19 +0300 Subject: [PATCH] Add column boundary check in the autocompletion. --- scene/gui/code_edit.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 5ce97d93b20..2c666cd5654 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -2381,6 +2381,7 @@ void CodeEdit::confirm_code_completion(bool p_replace) { } // Handle merging of symbols eg strings, brackets. + caret_line = get_caret_line(i); const String line = get_line(caret_line); char32_t next_char = line[get_caret_column(i)]; char32_t last_completion_char = insert_text[insert_text.length() - 1]; @@ -3024,17 +3025,18 @@ void CodeEdit::_bind_methods() { /* Auto brace completion */ int CodeEdit::_get_auto_brace_pair_open_at_pos(int p_line, int p_col) { const String &line = get_line(p_line); + int caret_col = MIN(p_col, line.length()); /* Should be fast enough, expecting low amount of pairs... */ for (int i = 0; i < auto_brace_completion_pairs.size(); i++) { const String &open_key = auto_brace_completion_pairs[i].open_key; - if (p_col - open_key.length() < 0) { + if (caret_col < open_key.length()) { continue; } bool is_match = true; for (int j = 0; j < open_key.length(); j++) { - if (line[(p_col - 1) - j] != open_key[(open_key.length() - 1) - j]) { + if (line[(caret_col - 1) - j] != open_key[(open_key.length() - 1) - j]) { is_match = false; break; }