@@ -108,6 +108,7 @@ void FindReplaceBar::_notification(int p_what) {
108108 hide_button->set_texture_hover (get_editor_theme_icon (SNAME (" Close" )));
109109 hide_button->set_texture_pressed (get_editor_theme_icon (SNAME (" Close" )));
110110 hide_button->set_custom_minimum_size (hide_button->get_texture_normal ()->get_size ());
111+ _update_toggle_replace_button (replace_text->is_visible_in_tree ());
111112 } break ;
112113
113114 case NOTIFICATION_VISIBILITY_CHANGED: {
@@ -539,6 +540,14 @@ void FindReplaceBar::_hide_bar(bool p_force_focus) {
539540 hide ();
540541}
541542
543+ void FindReplaceBar::_update_toggle_replace_button (bool p_replace_visible) {
544+ String tooltip = p_replace_visible ? TTR (" Hide Replace" ) : TTR (" Show Replace" );
545+ String shortcut = ED_GET_SHORTCUT (p_replace_visible ? " script_text_editor/find" : " script_text_editor/replace" )->get_as_text ();
546+ toggle_replace_button->set_tooltip_text (vformat (" %s (%s)" , tooltip, shortcut));
547+ StringName rtl_compliant_arrow = is_layout_rtl () ? SNAME (" GuiTreeArrowLeft" ) : SNAME (" GuiTreeArrowRight" );
548+ toggle_replace_button->set_icon (get_editor_theme_icon (p_replace_visible ? SNAME (" GuiTreeArrowDown" ) : rtl_compliant_arrow));
549+ }
550+
542551void FindReplaceBar::_show_search (bool p_with_replace, bool p_show_only) {
543552 show ();
544553 if (p_show_only) {
@@ -582,6 +591,7 @@ void FindReplaceBar::popup_search(bool p_show_only) {
582591 hbc_button_replace->hide ();
583592 hbc_option_replace->hide ();
584593 selection_only->set_pressed (false );
594+ _update_toggle_replace_button (false );
585595
586596 _show_search (false , p_show_only);
587597}
@@ -591,6 +601,7 @@ void FindReplaceBar::popup_replace() {
591601 replace_text->show ();
592602 hbc_button_replace->show ();
593603 hbc_option_replace->show ();
604+ _update_toggle_replace_button (true );
594605 }
595606
596607 selection_only->set_pressed (text_editor->has_selection (0 ) && text_editor->get_selection_from_line (0 ) < text_editor->get_selection_to_line (0 ));
@@ -644,6 +655,11 @@ void FindReplaceBar::_replace_text_submitted(const String &p_text) {
644655 }
645656}
646657
658+ void FindReplaceBar::_toggle_replace_pressed () {
659+ bool replace_visible = replace_text->is_visible_in_tree ();
660+ replace_visible ? popup_search (true ) : popup_replace ();
661+ }
662+
647663String FindReplaceBar::get_search_text () const {
648664 return search_text->get_text ();
649665}
@@ -702,6 +718,12 @@ void FindReplaceBar::_bind_methods() {
702718}
703719
704720FindReplaceBar::FindReplaceBar () {
721+ toggle_replace_button = memnew (Button);
722+ add_child (toggle_replace_button);
723+ toggle_replace_button->set_flat (true );
724+ toggle_replace_button->set_focus_mode (FOCUS_NONE);
725+ toggle_replace_button->connect (SceneStringName (pressed), callable_mp (this , &FindReplaceBar::_toggle_replace_pressed));
726+
705727 vbc_lineedit = memnew (VBoxContainer);
706728 add_child (vbc_lineedit);
707729 vbc_lineedit->set_alignment (BoxContainer::ALIGNMENT_CENTER);
0 commit comments