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

Fix FindReplaceBar focus problems #83335

Merged
merged 1 commit into from
Oct 16, 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
15 changes: 12 additions & 3 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ void FindReplaceBar::unhandled_input(const Ref<InputEvent> &p_event) {
}
}

void FindReplaceBar::_focus_lost() {
if (Input::get_singleton()->is_action_pressed(SNAME("ui_cancel"))) {
// Unfocused after pressing Escape, so hide the bar.
_hide_bar(true);
}
}

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 @@ -499,8 +506,8 @@ bool FindReplaceBar::search_next() {
return _search(flags, line, col);
}

void FindReplaceBar::_hide_bar() {
if (replace_text->has_focus() || search_text->has_focus()) {
void FindReplaceBar::_hide_bar(bool p_force_focus) {
if (replace_text->has_focus() || search_text->has_focus() || p_force_focus) {
text_editor->grab_focus();
}

Expand Down Expand Up @@ -698,6 +705,7 @@ FindReplaceBar::FindReplaceBar() {
search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
search_text->connect("text_changed", callable_mp(this, &FindReplaceBar::_search_text_changed));
search_text->connect("text_submitted", callable_mp(this, &FindReplaceBar::_search_text_submitted));
search_text->connect("focus_exited", callable_mp(this, &FindReplaceBar::_focus_lost));

matches_label = memnew(Label);
hbc_button_search->add_child(matches_label);
Expand Down Expand Up @@ -732,6 +740,7 @@ FindReplaceBar::FindReplaceBar() {
vbc_lineedit->add_child(replace_text);
replace_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
replace_text->connect("text_submitted", callable_mp(this, &FindReplaceBar::_replace_text_submitted));
replace_text->connect("focus_exited", callable_mp(this, &FindReplaceBar::_focus_lost));

replace = memnew(Button);
hbc_button_replace->add_child(replace);
Expand Down Expand Up @@ -773,7 +782,7 @@ void CodeTextEditor::input(const Ref<InputEvent> &event) {
}

if (!text_editor->has_focus()) {
if ((find_replace_bar != nullptr && find_replace_bar->is_visible()) && (find_replace_bar->has_focus() || find_replace_bar->is_ancestor_of(get_viewport()->gui_get_focus_owner()))) {
if ((find_replace_bar != nullptr && find_replace_bar->is_visible()) && (find_replace_bar->has_focus() || (get_viewport()->gui_get_focus_owner() && find_replace_bar->is_ancestor_of(get_viewport()->gui_get_focus_owner())))) {
if (ED_IS_SHORTCUT("script_text_editor/find_next", key_event)) {
find_replace_bar->search_next();
accept_event();
Expand Down
3 changes: 2 additions & 1 deletion editor/code_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class FindReplaceBar : public HBoxContainer {
void _update_matches_label();

void _show_search(bool p_focus_replace = false, bool p_show_only = false);
void _hide_bar();
void _hide_bar(bool p_force_focus = false);

void _editor_text_changed();
void _search_options_changed(bool p_pressed);
Expand All @@ -108,6 +108,7 @@ class FindReplaceBar : public HBoxContainer {
protected:
void _notification(int p_what);
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
void _focus_lost();

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

Expand Down
Loading