Deduplicate prev/next matches button code in search bars
This commit is contained in:
parent
bce501c696
commit
ccd5fc20bd
1 changed files with 15 additions and 49 deletions
|
@ -3,7 +3,7 @@ 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_text_input, toggle_replace_button},
|
search_bar::{input_base_styles, render_nav_button, render_text_input, toggle_replace_button},
|
||||||
};
|
};
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet};
|
||||||
|
@ -2052,54 +2052,20 @@ impl Render for ProjectSearchBar {
|
||||||
.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(
|
.child(render_nav_button(
|
||||||
IconButton::new("project-search-prev-match", IconName::ChevronLeft)
|
IconName::ChevronLeft,
|
||||||
.shape(IconButtonShape::Square)
|
search.active_match_index.is_some(),
|
||||||
.disabled(search.active_match_index.is_none())
|
"Select Previous Match",
|
||||||
.on_click(cx.listener(|this, _, window, cx| {
|
&SelectPreviousMatch,
|
||||||
if let Some(search) = this.active_project_search.as_ref() {
|
focus_handle.clone(),
|
||||||
search.update(cx, |this, cx| {
|
))
|
||||||
this.select_match(Direction::Prev, window, cx);
|
.child(render_nav_button(
|
||||||
})
|
IconName::ChevronRight,
|
||||||
}
|
search.active_match_index.is_some(),
|
||||||
}))
|
"Select Next Match",
|
||||||
.tooltip({
|
&SelectNextMatch,
|
||||||
let focus_handle = focus_handle.clone();
|
focus_handle.clone(),
|
||||||
move |window, cx| {
|
))
|
||||||
Tooltip::for_action_in(
|
|
||||||
"Go To Previous Match",
|
|
||||||
&SelectPreviousMatch,
|
|
||||||
&focus_handle,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
IconButton::new("project-search-next-match", IconName::ChevronRight)
|
|
||||||
.shape(IconButtonShape::Square)
|
|
||||||
.disabled(search.active_match_index.is_none())
|
|
||||||
.on_click(cx.listener(|this, _, window, cx| {
|
|
||||||
if let Some(search) = this.active_project_search.as_ref() {
|
|
||||||
search.update(cx, |this, cx| {
|
|
||||||
this.select_match(Direction::Next, window, cx);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.tooltip({
|
|
||||||
let focus_handle = focus_handle.clone();
|
|
||||||
move |window, cx| {
|
|
||||||
Tooltip::for_action_in(
|
|
||||||
"Go To Next Match",
|
|
||||||
&SelectNextMatch,
|
|
||||||
&focus_handle,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.id("matches")
|
.id("matches")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue