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,
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",

View file

@ -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",

View file

@ -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)