From 7408b338952dd60a495ad010474be76a02d5acdf Mon Sep 17 00:00:00 2001 From: megalobyte Date: Sat, 5 Jun 2021 00:27:49 -0700 Subject: [PATCH] Fix previous search for built-in-docs --- editor/editor_help.cpp | 2 +- scene/gui/rich_text_label.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 30f6e57dce6..051c0262817 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1737,7 +1737,7 @@ void FindBar::_update_results_count() { int from_pos = 0; while (true) { - int pos = full_text.find(searched, from_pos); + int pos = full_text.findn(searched, from_pos); if (pos == -1) { break; } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index ba0b9d1be84..c86c57ce887 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -2460,13 +2460,19 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p if (p_from_selection && selection.active) { it = selection.to; - charidx = selection.to_char + 1; + charidx = p_search_previous ? selection.from_char - 1 : selection.to_char + 1; + } + + if (charidx == -1) { + // At beginning of line and searching backwards + it = _get_prev_item(it, true); } while (it) { if (it->type == ITEM_TEXT) { ItemText *t = static_cast(it); - int sp = t->text.findn(p_string, charidx); + int sp = p_search_previous ? t->text.rfindn(p_string, charidx) : t->text.findn(p_string, charidx); + if (sp != -1) { selection.from = it; selection.from_char = sp; @@ -2501,10 +2507,11 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p if (p_search_previous) { it = _get_prev_item(it, true); + charidx = -1; } else { it = _get_next_item(it, true); + charidx = 0; } - charidx = 0; } return false;