From 0806343998a046d67ebf545a69a4174953bcd5cb Mon Sep 17 00:00:00 2001 From: kit Date: Wed, 4 Feb 2026 14:30:58 -0500 Subject: [PATCH] Fix TextEdit backwards search skipping matches --- scene/gui/text_edit.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 8a023acc57..63355b1116 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -4895,6 +4895,11 @@ Point2i TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_fro int current_line = p_from_line; int current_column = p_from_column; + if (p_search_flags & SEARCH_BACKWARDS) { + // `rfind` requires the from index to be within the bounds of the last possible match position. + current_column = MIN(current_column, text[p_from_line].length() - p_key.length()); + } + // + 1 because we'll search p_from_line twice - starting from p_from_column, and then again at the very end. for (int i = 0; i < text.size() + 1; i++) { const String &text_line = text[current_line];