Merge pull request #82707 from BrianMacIntosh/find-highlight-fix

Search terms are now highlighted when the bar opens with a selection.
This commit is contained in:
Rémi Verschelde 2023-10-30 23:17:45 +01:00
commit ec5bfbd176
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 22 additions and 30 deletions

View file

@ -141,6 +141,20 @@ void FindReplaceBar::_focus_lost() {
} }
} }
void FindReplaceBar::_update_flags(bool p_direction_backwards) {
flags = 0;
if (is_whole_words()) {
flags |= TextEdit::SEARCH_WHOLE_WORDS;
}
if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
}
if (p_direction_backwards) {
flags |= TextEdit::SEARCH_BACKWARDS;
}
}
bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) { bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) {
if (!preserve_cursor) { if (!preserve_cursor) {
text_editor->remove_secondary_carets(); text_editor->remove_secondary_carets();
@ -431,14 +445,7 @@ void FindReplaceBar::_update_matches_label() {
} }
bool FindReplaceBar::search_current() { bool FindReplaceBar::search_current() {
flags = 0; _update_flags(false);
if (is_whole_words()) {
flags |= TextEdit::SEARCH_WHOLE_WORDS;
}
if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
}
int line, col; int line, col;
_get_search_from(line, col); _get_search_from(line, col);
@ -455,17 +462,9 @@ bool FindReplaceBar::search_prev() {
popup_search(true); popup_search(true);
} }
flags = 0;
String text = get_search_text(); String text = get_search_text();
if (is_whole_words()) { _update_flags(true);
flags |= TextEdit::SEARCH_WHOLE_WORDS;
}
if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
}
flags |= TextEdit::SEARCH_BACKWARDS;
int line, col; int line, col;
_get_search_from(line, col); _get_search_from(line, col);
@ -491,14 +490,7 @@ bool FindReplaceBar::search_next() {
popup_search(true); popup_search(true);
} }
flags = 0; _update_flags(false);
if (is_whole_words()) {
flags |= TextEdit::SEARCH_WHOLE_WORDS;
}
if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
}
int line, col; int line, col;
_get_search_from(line, col, true); _get_search_from(line, col, true);
@ -546,11 +538,9 @@ void FindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) {
search_text->set_caret_column(search_text->get_text().length()); search_text->set_caret_column(search_text->get_text().length());
} }
results_count = -1; preserve_cursor = true;
results_count_to_current = -1; _search_text_changed(get_search_text());
needs_to_count_results = true; preserve_cursor = false;
_update_results_count();
_update_matches_label();
} }
} }

View file

@ -110,6 +110,8 @@ protected:
virtual void unhandled_input(const Ref<InputEvent> &p_event) override; virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
void _focus_lost(); void _focus_lost();
void _update_flags(bool p_direction_backwards);
bool _search(uint32_t p_flags, int p_from_line, int p_from_col); bool _search(uint32_t p_flags, int p_from_line, int p_from_col);
void _replace(); void _replace();