Skip to content

Commit

Permalink
Merge pull request #102296 from kitbdev/fix-te-remove-range-line-count
Browse files Browse the repository at this point in the history
Fix TextEdit visible line count when setting text
  • Loading branch information
Repiteo committed Feb 4, 2025
2 parents 92ebcd2 + 0a19f89 commit 0746447
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,11 @@ void TextEdit::Text::insert(int p_at, const Vector<String> &p_text, const Vector
}

void TextEdit::Text::remove_range(int p_from_line, int p_to_line) {
p_from_line = MAX(p_from_line, 0);
ERR_FAIL_INDEX(p_from_line, text.size());

p_to_line = MIN(p_to_line, text.size());
ERR_FAIL_COND(p_to_line < p_from_line);

if (p_from_line == p_to_line) {
return;
}

for (int i = p_from_line; i < p_to_line; i++) {
for (int i = p_from_line + 1; i <= p_to_line; i++) {
const Line &text_line = text[i];
if (text_line.hidden) {
continue;
Expand All @@ -435,9 +429,9 @@ void TextEdit::Text::remove_range(int p_from_line, int p_to_line) {
total_visible_line_count -= text_line.line_count;
}

int diff = (p_to_line - p_from_line);
for (int i = p_to_line; i < text.size() - 1; i++) {
text.write[(i - diff) + 1] = text[i + 1];
int diff = p_to_line - p_from_line;
for (int i = p_to_line + 1; i < text.size(); i++) {
text.write[i - diff] = text[i];
}
text.resize(text.size() - diff);

Expand Down

0 comments on commit 0746447

Please sign in to comment.