From 290180c89984cb5236c81e3f778d183026fdfbd1 Mon Sep 17 00:00:00 2001 From: kit Date: Mon, 20 Oct 2025 17:42:38 -0400 Subject: [PATCH] Fix TextEdit IME error on mouse over --- scene/gui/text_edit.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index f97c217e64..c7530e5eb4 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -4974,7 +4974,7 @@ String TextEdit::get_word(int p_line, int p_column) const { } ERR_FAIL_INDEX_V(p_line, text.size(), String()); - const String &text_line = text[p_line]; + const String &text_line = text.get_text_with_ime(p_line); if (text_line.is_empty()) { return String(); } @@ -6386,24 +6386,20 @@ int TextEdit::get_line_wrap_count(int p_line) const { int TextEdit::get_line_wrap_index_at_column(int p_line, int p_column) const { ERR_FAIL_INDEX_V(p_line, text.size(), 0); ERR_FAIL_COND_V(p_column < 0, 0); - ERR_FAIL_COND_V(p_column > text[p_line].length(), 0); + ERR_FAIL_COND_V(p_column > text.get_text_with_ime(p_line).length(), 0); if (!is_line_wrapped(p_line)) { return 0; } - /* Loop through wraps in the line text until we get to the column. */ - int wrap_index = 0; - int col = 0; - Vector lines = get_line_wrapped_text(p_line); - for (int i = 0; i < lines.size(); i++) { - wrap_index = i; - col += lines[wrap_index].length(); - if (col > p_column) { - break; + // Loop through wraps in the line text until we get to the column. + const Vector line_ranges = text.get_line_wrap_ranges(p_line); + for (int i = 0; i < line_ranges.size(); i++) { + if (line_ranges[i].y > p_column) { + return i; } } - return wrap_index; + return line_ranges.is_empty() ? 0 : line_ranges.size() - 1; } Vector TextEdit::get_line_wrapped_text(int p_line) const { @@ -6411,12 +6407,13 @@ Vector TextEdit::get_line_wrapped_text(int p_line) const { Vector lines; if (!is_line_wrapped(p_line)) { - lines.push_back(text[p_line]); + lines.push_back(text.get_text_with_ime(p_line)); return lines; } - const String &line_text = text[p_line]; - Vector line_ranges = text.get_line_wrap_ranges(p_line); + const String &line_text = text.get_text_with_ime(p_line); + const Vector line_ranges = text.get_line_wrap_ranges(p_line); + lines.reserve(line_ranges.size()); for (int i = 0; i < line_ranges.size(); i++) { lines.push_back(line_text.substr(line_ranges[i].x, line_ranges[i].y - line_ranges[i].x)); }