Fix previous search for built-in-docs

This commit is contained in:
megalobyte 2021-06-05 00:27:49 -07:00 committed by Gregory Basile
parent f102ba8b2f
commit 7408b33895
2 changed files with 11 additions and 4 deletions

View file

@ -1737,7 +1737,7 @@ void FindBar::_update_results_count() {
int from_pos = 0; int from_pos = 0;
while (true) { while (true) {
int pos = full_text.find(searched, from_pos); int pos = full_text.findn(searched, from_pos);
if (pos == -1) { if (pos == -1) {
break; break;
} }

View file

@ -2460,13 +2460,19 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
if (p_from_selection && selection.active) { if (p_from_selection && selection.active) {
it = selection.to; 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) { while (it) {
if (it->type == ITEM_TEXT) { if (it->type == ITEM_TEXT) {
ItemText *t = static_cast<ItemText *>(it); ItemText *t = static_cast<ItemText *>(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) { if (sp != -1) {
selection.from = it; selection.from = it;
selection.from_char = sp; 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) { if (p_search_previous) {
it = _get_prev_item(it, true); it = _get_prev_item(it, true);
charidx = -1;
} else { } else {
it = _get_next_item(it, true); it = _get_next_item(it, true);
charidx = 0;
} }
charidx = 0;
} }
return false; return false;