Merge pull request #115876 from kitbdev/fix-te-search-backwards

Fix TextEdit backwards search skipping matches
This commit is contained in:
Thaddeus Crews 2026-02-20 11:36:08 -06:00
commit 781ae8deb2
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC

View file

@ -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];