Cleanup render_action_button some more

This commit is contained in:
Lukas Wirth 2025-08-13 12:08:07 +02:00
parent 88daa45537
commit e2ab26ef41
3 changed files with 32 additions and 16 deletions

View file

@ -4,7 +4,9 @@ use crate::{
FocusSearch, NextHistoryQuery, PreviousHistoryQuery, ReplaceAll, ReplaceNext, SearchOptions, FocusSearch, NextHistoryQuery, PreviousHistoryQuery, ReplaceAll, ReplaceNext, SearchOptions,
SelectAllMatches, SelectNextMatch, SelectPreviousMatch, ToggleCaseSensitive, ToggleRegex, SelectAllMatches, SelectNextMatch, SelectPreviousMatch, ToggleCaseSensitive, ToggleRegex,
ToggleReplace, ToggleSelection, ToggleWholeWord, 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 any_vec::AnyVec;
use anyhow::Context as _; use anyhow::Context as _;
@ -282,24 +284,27 @@ impl Render for BufferSearchBar {
) )
}) })
.when(!supported_options.find_in_results, |el| { .when(!supported_options.find_in_results, |el| {
let query_focus = self.query_editor.focus_handle(cx);
let matches_column = h_flex() let matches_column = h_flex()
.pl_2() .pl_2()
.ml_1() .ml_1()
.border_l_1() .border_l_1()
.border_color(cx.theme().colors().border_variant) .border_color(cx.theme().colors().border_variant)
.child(render_nav_button( .child(render_action_button(
"buffer-search-nav-button",
ui::IconName::ChevronLeft, ui::IconName::ChevronLeft,
self.active_match_index.is_some(), self.active_match_index.is_some(),
"Select Previous Match", "Select Previous Match",
&SelectPreviousMatch, &SelectPreviousMatch,
focus_handle.clone(), query_focus.clone(),
)) ))
.child(render_nav_button( .child(render_action_button(
"buffer-search-nav-button",
ui::IconName::ChevronRight, ui::IconName::ChevronRight,
self.active_match_index.is_some(), self.active_match_index.is_some(),
"Select Next Match", "Select Next Match",
&SelectNextMatch, &SelectNextMatch,
focus_handle.clone(), query_focus,
)); ));
el.child( el.child(
IconButton::new("select-all", ui::IconName::SelectAll) IconButton::new("select-all", ui::IconName::SelectAll)
@ -363,14 +368,16 @@ impl Render for BufferSearchBar {
let replace_actions = h_flex() let replace_actions = h_flex()
.min_w_64() .min_w_64()
.gap_1() .gap_1()
.child(render_nav_button( .child(render_action_button(
"buffer-search-replace-button",
IconName::ReplaceNext, IconName::ReplaceNext,
true, true,
"Replace Next Match", "Replace Next Match",
&ReplaceNext, &ReplaceNext,
focus_handle.clone(), focus_handle.clone(),
)) ))
.child(render_nav_button( .child(render_action_button(
"buffer-search-replace-button",
IconName::ReplaceAll, IconName::ReplaceAll,
true, true,
"Replace All Matches", "Replace All Matches",

View file

@ -3,7 +3,9 @@ use crate::{
SearchOptions, SelectNextMatch, SelectPreviousMatch, ToggleCaseSensitive, ToggleIncludeIgnored, SearchOptions, SelectNextMatch, SelectPreviousMatch, ToggleCaseSensitive, ToggleIncludeIgnored,
ToggleRegex, ToggleReplace, ToggleWholeWord, ToggleRegex, ToggleReplace, ToggleWholeWord,
buffer_search::Deploy, 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 anyhow::Context as _;
use collections::{HashMap, HashSet}; 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() let matches_column = h_flex()
.pl_2() .pl_2()
.ml_2() .ml_2()
.border_l_1() .border_l_1()
.border_color(cx.theme().colors().border_variant) .border_color(cx.theme().colors().border_variant)
.child(render_nav_button( .child(render_action_button(
"project-search-nav-button",
IconName::ChevronLeft, IconName::ChevronLeft,
search.active_match_index.is_some(), search.active_match_index.is_some(),
"Select Previous Match", "Select Previous Match",
&SelectPreviousMatch, &SelectPreviousMatch,
focus_handle.clone(), query_focus.clone(),
)) ))
.child(render_nav_button( .child(render_action_button(
"project-search-nav-button",
IconName::ChevronRight, IconName::ChevronRight,
search.active_match_index.is_some(), search.active_match_index.is_some(),
"Select Next Match", "Select Next Match",
&SelectNextMatch, &SelectNextMatch,
focus_handle.clone(), query_focus,
)) ))
.child( .child(
div() div()
@ -2099,14 +2105,16 @@ impl Render for ProjectSearchBar {
let replace_actions = h_flex() let replace_actions = h_flex()
.min_w_64() .min_w_64()
.gap_1() .gap_1()
.child(render_nav_button( .child(render_action_button(
"project-search-replace-button",
IconName::ReplaceNext, IconName::ReplaceNext,
true, true,
"Replace Next Match", "Replace Next Match",
&ReplaceNext, &ReplaceNext,
focus_handle.clone(), focus_handle.clone(),
)) ))
.child(render_nav_button( .child(render_action_button(
"project-search-replace-button",
IconName::ReplaceAll, IconName::ReplaceAll,
true, true,
"Replace All Matches", "Replace All Matches",

View file

@ -7,7 +7,8 @@ use ui::{Tooltip, prelude::*};
use crate::ToggleReplace; use crate::ToggleReplace;
pub(super) fn render_nav_button( pub(super) fn render_action_button(
id_prefix: &'static str,
icon: ui::IconName, icon: ui::IconName,
active: bool, active: bool,
tooltip: &'static str, tooltip: &'static str,
@ -15,7 +16,7 @@ pub(super) fn render_nav_button(
focus_handle: FocusHandle, focus_handle: FocusHandle,
) -> impl IntoElement { ) -> impl IntoElement {
IconButton::new( IconButton::new(
SharedString::from(format!("search-nav-button-{}", action.name())), SharedString::from(format!("{id_prefix}-{}", action.name())),
icon, icon,
) )
.shape(IconButtonShape::Square) .shape(IconButtonShape::Square)