Skip to content

Commit 480f3d1

Browse files
committed
Merge pull request godotengine#110017 from bruvzg/acomp_col_check
Add column boundary check in the autocompletion.
2 parents 60b7b8b + 1c50f86 commit 480f3d1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

scene/gui/code_edit.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,7 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
23812381
}
23822382

23832383
// Handle merging of symbols eg strings, brackets.
2384+
caret_line = get_caret_line(i);
23842385
const String line = get_line(caret_line);
23852386
char32_t next_char = line[get_caret_column(i)];
23862387
char32_t last_completion_char = insert_text[insert_text.length() - 1];
@@ -3024,17 +3025,18 @@ void CodeEdit::_bind_methods() {
30243025
/* Auto brace completion */
30253026
int CodeEdit::_get_auto_brace_pair_open_at_pos(int p_line, int p_col) {
30263027
const String &line = get_line(p_line);
3028+
int caret_col = MIN(p_col, line.length());
30273029

30283030
/* Should be fast enough, expecting low amount of pairs... */
30293031
for (int i = 0; i < auto_brace_completion_pairs.size(); i++) {
30303032
const String &open_key = auto_brace_completion_pairs[i].open_key;
3031-
if (p_col - open_key.length() < 0) {
3033+
if (caret_col < open_key.length()) {
30323034
continue;
30333035
}
30343036

30353037
bool is_match = true;
30363038
for (int j = 0; j < open_key.length(); j++) {
3037-
if (line[(p_col - 1) - j] != open_key[(open_key.length() - 1) - j]) {
3039+
if (line[(caret_col - 1) - j] != open_key[(open_key.length() - 1) - j]) {
30383040
is_match = false;
30393041
break;
30403042
}

0 commit comments

Comments
 (0)