Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search terms are now highlighted when the bar opens with a selection. #82707

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 20 additions & 30 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if (!preserve_cursor) {
text_editor->remove_secondary_carets();
Expand Down Expand Up @@ -431,14 +445,7 @@ void FindReplaceBar::_update_matches_label() {
}

bool FindReplaceBar::search_current() {
flags = 0;

if (is_whole_words()) {
flags |= TextEdit::SEARCH_WHOLE_WORDS;
}
if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
}
_update_flags(false);

int line, col;
_get_search_from(line, col);
Expand All @@ -455,17 +462,9 @@ bool FindReplaceBar::search_prev() {
popup_search(true);
}

flags = 0;
String text = get_search_text();

if (is_whole_words()) {
flags |= TextEdit::SEARCH_WHOLE_WORDS;
}
if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
}

flags |= TextEdit::SEARCH_BACKWARDS;
_update_flags(true);

int line, col;
_get_search_from(line, col);
Expand All @@ -491,14 +490,7 @@ bool FindReplaceBar::search_next() {
popup_search(true);
}

flags = 0;

if (is_whole_words()) {
flags |= TextEdit::SEARCH_WHOLE_WORDS;
}
if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
}
_update_flags(false);

int line, col;
_get_search_from(line, col, true);
Expand Down Expand Up @@ -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());
}

results_count = -1;
results_count_to_current = -1;
needs_to_count_results = true;
_update_results_count();
_update_matches_label();
preserve_cursor = true;
_search_text_changed(get_search_text());
YuriSizov marked this conversation as resolved.
Show resolved Hide resolved
preserve_cursor = false;
}
}

Expand Down
2 changes: 2 additions & 0 deletions editor/code_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class FindReplaceBar : public HBoxContainer {
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
void _focus_lost();

void _update_flags(bool p_direction_backwards);

bool _search(uint32_t p_flags, int p_from_line, int p_from_col);

void _replace();
Expand Down
Loading