Skip to content

Commit

Permalink
fixup! Move away from using cx.dispatch_action in buffer search
Browse files Browse the repository at this point in the history
  • Loading branch information
osiewicz committed Dec 12, 2023
1 parent be57059 commit 13f9fec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 14 additions & 3 deletions crates/search2/src/buffer_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,21 @@ impl Render for BufferSearchBar {
Some(ui::Label::new(message))
});
let should_show_replace_input = self.replace_enabled && supported_options.replacement;
let replace_all = should_show_replace_input
.then(|| super::render_replace_button(ReplaceAll, ui::Icon::ReplaceAll, "Replace all"));
let replace_all = should_show_replace_input.then(|| {
super::render_replace_button(
ReplaceAll,
ui::Icon::ReplaceAll,
"Replace all",
cx.listener(|this, _, cx| this.replace_all(&ReplaceAll, cx)),
)
});
let replace_next = should_show_replace_input.then(|| {
super::render_replace_button(ReplaceNext, ui::Icon::ReplaceNext, "Replace next")
super::render_replace_button(
ReplaceNext,
ui::Icon::ReplaceNext,
"Replace next",
cx.listener(|this, _, cx| this.replace_next(&ReplaceNext, cx)),
)
});
let in_replace = self.replacement_editor.focus_handle(cx).is_focused(cx);

Expand Down
5 changes: 2 additions & 3 deletions crates/search2/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ fn render_replace_button(
action: impl Action + 'static + Send + Sync,
icon: Icon,
tooltip: &'static str,
on_click: impl Fn(&gpui::ClickEvent, &mut WindowContext) + 'static,
) -> impl IntoElement {
let id: SharedString = format!("search-replace-{}", action.name()).into();
IconButton::new(id, icon)
.tooltip({
let action = action.boxed_clone();
move |cx| Tooltip::for_action(tooltip, &*action, cx)
})
.on_click(move |_, cx| {
cx.dispatch_action(action.boxed_clone());
})
.on_click(on_click)
}

0 comments on commit 13f9fec

Please sign in to comment.