Browse Source

Merge pull request #49332 from megalobyte/doc-prev-search

[3.x] Fix previous search for built-in-docs
Rémi Verschelde 4 years ago
parent
commit
d84d5a9665
2 changed files with 11 additions and 4 deletions
  1. 1 1
      editor/editor_help.cpp
  2. 10 3
      scene/gui/rich_text_label.cpp

+ 1 - 1
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;
 		}

+ 10 - 3
scene/gui/rich_text_label.cpp

@@ -2481,13 +2481,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<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) {
 				selection.from = it;
 				selection.from_char = sp;
@@ -2522,10 +2528,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;