From e2ab26ef414071398194ee5cd7f3f254eb05e4a4 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 13 Aug 2025 12:08:07 +0200 Subject: [PATCH] Cleanup `render_action_button` some more --- crates/search/src/buffer_search.rs | 21 ++++++++++++++------- crates/search/src/project_search.rs | 22 +++++++++++++++------- crates/search/src/search_bar.rs | 5 +++-- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index f9c3c1eb30244c324a6a854ab6ad7afb51d194aa..aace19e5eecca26942f43835a8a987261f09cbad 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -4,7 +4,9 @@ use crate::{ FocusSearch, NextHistoryQuery, PreviousHistoryQuery, ReplaceAll, ReplaceNext, SearchOptions, SelectAllMatches, SelectNextMatch, SelectPreviousMatch, ToggleCaseSensitive, ToggleRegex, ToggleReplace, ToggleSelection, ToggleWholeWord, - search_bar::{input_base_styles, render_nav_button, render_text_input, toggle_replace_button}, + search_bar::{ + input_base_styles, render_action_button, render_text_input, toggle_replace_button, + }, }; use any_vec::AnyVec; use anyhow::Context as _; @@ -282,24 +284,27 @@ impl Render for BufferSearchBar { ) }) .when(!supported_options.find_in_results, |el| { + let query_focus = self.query_editor.focus_handle(cx); let matches_column = h_flex() .pl_2() .ml_1() .border_l_1() .border_color(cx.theme().colors().border_variant) - .child(render_nav_button( + .child(render_action_button( + "buffer-search-nav-button", ui::IconName::ChevronLeft, self.active_match_index.is_some(), "Select Previous Match", &SelectPreviousMatch, - focus_handle.clone(), + query_focus.clone(), )) - .child(render_nav_button( + .child(render_action_button( + "buffer-search-nav-button", ui::IconName::ChevronRight, self.active_match_index.is_some(), "Select Next Match", &SelectNextMatch, - focus_handle.clone(), + query_focus, )); el.child( IconButton::new("select-all", ui::IconName::SelectAll) @@ -363,14 +368,16 @@ impl Render for BufferSearchBar { let replace_actions = h_flex() .min_w_64() .gap_1() - .child(render_nav_button( + .child(render_action_button( + "buffer-search-replace-button", IconName::ReplaceNext, true, "Replace Next Match", &ReplaceNext, focus_handle.clone(), )) - .child(render_nav_button( + .child(render_action_button( + "buffer-search-replace-button", IconName::ReplaceAll, true, "Replace All Matches", diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index b90c229dbb574ed2f5e248d066d88dfedac9a129..e68e4509ff8fc26bde83c4206489b7c0aa3b8b9a 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -3,7 +3,9 @@ use crate::{ SearchOptions, SelectNextMatch, SelectPreviousMatch, ToggleCaseSensitive, ToggleIncludeIgnored, ToggleRegex, ToggleReplace, ToggleWholeWord, buffer_search::Deploy, - search_bar::{input_base_styles, render_nav_button, render_text_input, toggle_replace_button}, + search_bar::{ + input_base_styles, render_action_button, render_text_input, toggle_replace_button, + }, }; use anyhow::Context as _; use collections::{HashMap, HashSet}; @@ -2047,24 +2049,28 @@ impl Render for ProjectSearchBar { }), )); + let query_focus = search.query_editor.focus_handle(cx); + let matches_column = h_flex() .pl_2() .ml_2() .border_l_1() .border_color(cx.theme().colors().border_variant) - .child(render_nav_button( + .child(render_action_button( + "project-search-nav-button", IconName::ChevronLeft, search.active_match_index.is_some(), "Select Previous Match", &SelectPreviousMatch, - focus_handle.clone(), + query_focus.clone(), )) - .child(render_nav_button( + .child(render_action_button( + "project-search-nav-button", IconName::ChevronRight, search.active_match_index.is_some(), "Select Next Match", &SelectNextMatch, - focus_handle.clone(), + query_focus, )) .child( div() @@ -2099,14 +2105,16 @@ impl Render for ProjectSearchBar { let replace_actions = h_flex() .min_w_64() .gap_1() - .child(render_nav_button( + .child(render_action_button( + "project-search-replace-button", IconName::ReplaceNext, true, "Replace Next Match", &ReplaceNext, focus_handle.clone(), )) - .child(render_nav_button( + .child(render_action_button( + "project-search-replace-button", IconName::ReplaceAll, true, "Replace All Matches", diff --git a/crates/search/src/search_bar.rs b/crates/search/src/search_bar.rs index ba779beeb3bed15b224dccdfcbb3dc3756228025..2805b0c62d48ff7180d3076bc984ef597f96f28a 100644 --- a/crates/search/src/search_bar.rs +++ b/crates/search/src/search_bar.rs @@ -7,7 +7,8 @@ use ui::{Tooltip, prelude::*}; use crate::ToggleReplace; -pub(super) fn render_nav_button( +pub(super) fn render_action_button( + id_prefix: &'static str, icon: ui::IconName, active: bool, tooltip: &'static str, @@ -15,7 +16,7 @@ pub(super) fn render_nav_button( focus_handle: FocusHandle, ) -> impl IntoElement { IconButton::new( - SharedString::from(format!("search-nav-button-{}", action.name())), + SharedString::from(format!("{id_prefix}-{}", action.name())), icon, ) .shape(IconButtonShape::Square)