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; }