Deduplicate replace button code in search bars
This commit is contained in:
parent
ccd5fc20bd
commit
036bc75799
2 changed files with 42 additions and 100 deletions
|
@ -359,60 +359,34 @@ impl Render for BufferSearchBar {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
let replace_line = should_show_replace_input.then(|| {
|
let replace_line =
|
||||||
h_flex()
|
should_show_replace_input.then(|| {
|
||||||
.gap_2()
|
let replace_column = input_base_styles(replacement_border)
|
||||||
.child(
|
.child(render_text_input(&self.replacement_editor, None, cx));
|
||||||
input_base_styles(replacement_border).child(render_text_input(
|
let focus_handle = self.replacement_editor.read(cx).focus_handle(cx);
|
||||||
&self.replacement_editor,
|
|
||||||
None,
|
let replace_actions = h_flex()
|
||||||
cx,
|
.min_w_64()
|
||||||
)),
|
.gap_1()
|
||||||
)
|
.child(render_nav_button(
|
||||||
.child(
|
IconName::ReplaceNext,
|
||||||
h_flex()
|
true,
|
||||||
.min_w_64()
|
"Replace Next Match",
|
||||||
.gap_1()
|
&ReplaceNext,
|
||||||
.child(
|
focus_handle.clone(),
|
||||||
IconButton::new("search-replace-next", ui::IconName::ReplaceNext)
|
))
|
||||||
.shape(IconButtonShape::Square)
|
.child(render_nav_button(
|
||||||
.tooltip({
|
IconName::ReplaceAll,
|
||||||
let focus_handle = focus_handle.clone();
|
true,
|
||||||
move |window, cx| {
|
"Replace All Matches",
|
||||||
Tooltip::for_action_in(
|
&ReplaceAll,
|
||||||
"Replace Next Match",
|
focus_handle,
|
||||||
&ReplaceNext,
|
));
|
||||||
&focus_handle,
|
h_flex()
|
||||||
window,
|
.gap_2()
|
||||||
cx,
|
.child(replace_column)
|
||||||
)
|
.child(replace_actions)
|
||||||
}
|
});
|
||||||
})
|
|
||||||
.on_click(cx.listener(|this, _, window, cx| {
|
|
||||||
this.replace_next(&ReplaceNext, window, cx)
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
IconButton::new("search-replace-all", ui::IconName::ReplaceAll)
|
|
||||||
.shape(IconButtonShape::Square)
|
|
||||||
.tooltip({
|
|
||||||
let focus_handle = focus_handle.clone();
|
|
||||||
move |window, cx| {
|
|
||||||
Tooltip::for_action_in(
|
|
||||||
"Replace All Matches",
|
|
||||||
&ReplaceAll,
|
|
||||||
&focus_handle,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on_click(cx.listener(|this, _, window, cx| {
|
|
||||||
this.replace_all(&ReplaceAll, window, cx)
|
|
||||||
})),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let query_error_line = self.query_error.as_ref().map(|error| {
|
let query_error_line = self.query_error.as_ref().map(|error| {
|
||||||
Label::new(error)
|
Label::new(error)
|
||||||
|
|
|
@ -2099,52 +2099,20 @@ 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(
|
.child(render_nav_button(
|
||||||
IconButton::new("project-search-replace-next", IconName::ReplaceNext)
|
IconName::ReplaceNext,
|
||||||
.shape(IconButtonShape::Square)
|
true,
|
||||||
.on_click(cx.listener(|this, _, window, cx| {
|
"Replace Next Match",
|
||||||
if let Some(search) = this.active_project_search.as_ref() {
|
&ReplaceNext,
|
||||||
search.update(cx, |this, cx| {
|
focus_handle.clone(),
|
||||||
this.replace_next(&ReplaceNext, window, cx);
|
))
|
||||||
})
|
.child(render_nav_button(
|
||||||
}
|
IconName::ReplaceAll,
|
||||||
}))
|
true,
|
||||||
.tooltip({
|
"Replace All Matches",
|
||||||
let focus_handle = focus_handle.clone();
|
&ReplaceAll,
|
||||||
move |window, cx| {
|
focus_handle,
|
||||||
Tooltip::for_action_in(
|
));
|
||||||
"Replace Next Match",
|
|
||||||
&ReplaceNext,
|
|
||||||
&focus_handle,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
IconButton::new("project-search-replace-all", IconName::ReplaceAll)
|
|
||||||
.shape(IconButtonShape::Square)
|
|
||||||
.on_click(cx.listener(|this, _, window, cx| {
|
|
||||||
if let Some(search) = this.active_project_search.as_ref() {
|
|
||||||
search.update(cx, |this, cx| {
|
|
||||||
this.replace_all(&ReplaceAll, window, cx);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.tooltip({
|
|
||||||
let focus_handle = focus_handle.clone();
|
|
||||||
move |window, cx| {
|
|
||||||
Tooltip::for_action_in(
|
|
||||||
"Replace All Matches",
|
|
||||||
&ReplaceAll,
|
|
||||||
&focus_handle,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
h_flex()
|
h_flex()
|
||||||
.w_full()
|
.w_full()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue