Skip to content

Commit 0746447

Browse files
committed
Merge pull request #102296 from kitbdev/fix-te-remove-range-line-count
Fix TextEdit visible line count when setting text
2 parents 92ebcd2 + 0a19f89 commit 0746447

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

scene/gui/text_edit.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,17 +410,11 @@ void TextEdit::Text::insert(int p_at, const Vector<String> &p_text, const Vector
410410
}
411411

412412
void TextEdit::Text::remove_range(int p_from_line, int p_to_line) {
413-
p_from_line = MAX(p_from_line, 0);
414-
ERR_FAIL_INDEX(p_from_line, text.size());
415-
416-
p_to_line = MIN(p_to_line, text.size());
417-
ERR_FAIL_COND(p_to_line < p_from_line);
418-
419413
if (p_from_line == p_to_line) {
420414
return;
421415
}
422416

423-
for (int i = p_from_line; i < p_to_line; i++) {
417+
for (int i = p_from_line + 1; i <= p_to_line; i++) {
424418
const Line &text_line = text[i];
425419
if (text_line.hidden) {
426420
continue;
@@ -435,9 +429,9 @@ void TextEdit::Text::remove_range(int p_from_line, int p_to_line) {
435429
total_visible_line_count -= text_line.line_count;
436430
}
437431

438-
int diff = (p_to_line - p_from_line);
439-
for (int i = p_to_line; i < text.size() - 1; i++) {
440-
text.write[(i - diff) + 1] = text[i + 1];
432+
int diff = p_to_line - p_from_line;
433+
for (int i = p_to_line + 1; i < text.size(); i++) {
434+
text.write[i - diff] = text[i];
441435
}
442436
text.resize(text.size() - diff);
443437

0 commit comments

Comments
 (0)