diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index 123b53c98662f5b060df425a5f4ad57d5325e3cb..3674baf3569b64542bb3b7bb482a61fcef3f01bb 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -63,8 +63,8 @@ pub struct BufferSearchBar { impl EventEmitter for BufferSearchBar {} impl EventEmitter for BufferSearchBar {} -impl Render for BufferSearchBar { - type Element = Div; +impl Render for BufferSearchBar { + type Element = Div; fn render(&mut self, cx: &mut ViewContext) -> Self::Element { // let query_container_style = if self.query_contains_error { // theme.search.invalid_editor @@ -131,9 +131,13 @@ impl Render for BufferSearchBar { let search_button_for_mode = |mode| { let is_active = self.current_mode == mode; - render_search_mode_button(mode, is_active, move |this: &mut Self, cx| { - this.activate_search_mode(mode, cx); - }) + render_search_mode_button( + mode, + is_active, + cx.listener(move |this, _, cx| { + this.activate_search_mode(mode, cx); + }), + ) }; let search_option_button = |option| { let is_active = self.search_options.contains(option); @@ -161,28 +165,28 @@ impl Render for BufferSearchBar { render_nav_button( icon, self.active_match_index.is_some(), - move |this: &mut Self, cx| match direction { + cx.listener(move |this, _, cx| match direction { Direction::Prev => this.select_prev_match(&Default::default(), cx), Direction::Next => this.select_next_match(&Default::default(), cx), - }, + }), ) }; 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)); + .then(|| super::render_replace_button(ReplaceAll, ui::Icon::ReplaceAll)); let replace_next = should_show_replace_input - .then(|| super::render_replace_button::(ReplaceNext, ui::Icon::Replace)); + .then(|| super::render_replace_button(ReplaceNext, ui::Icon::Replace)); let in_replace = self.replacement_editor.focus_handle(cx).is_focused(cx); h_stack() .key_context("BufferSearchBar") .when(in_replace, |this| { this.key_context("in_replace") - .on_action(Self::replace_next) - .on_action(Self::replace_all) + .on_action(cx.listener(Self::replace_next)) + .on_action(cx.listener(Self::replace_all)) }) - .on_action(Self::previous_history_query) - .on_action(Self::next_history_query) + .on_action(cx.listener(Self::previous_history_query)) + .on_action(cx.listener(Self::next_history_query)) .w_full() .p_1() .child( @@ -534,13 +538,13 @@ impl BufferSearchBar { self.update_matches(cx) } - fn render_action_button(&self) -> impl RenderOnce { + fn render_action_button(&self) -> impl RenderOnce { // let tooltip_style = theme.tooltip.clone(); // let style = theme.search.action_button.clone(); IconButton::new(0, ui::Icon::SelectAll) - .on_click(|_: &mut Self, cx| cx.dispatch_action(Box::new(SelectAllMatches))) + .on_click(|_, cx| cx.dispatch_action(Box::new(SelectAllMatches))) } pub fn activate_search_mode(&mut self, mode: SearchMode, cx: &mut ViewContext) { @@ -883,7 +887,7 @@ mod tests { let store = settings::SettingsStore::test(cx); cx.set_global(store); editor::init(cx); - ui::init(cx); + language::init(cx); theme::init(theme::LoadThemes::JustBase, cx); }); diff --git a/crates/search2/src/search.rs b/crates/search2/src/search.rs index c138c49d34238d091d274c06264c7783b46ba887..12152701bc69fb9dce23ce00267dd4bea55dcb19 100644 --- a/crates/search2/src/search.rs +++ b/crates/search2/src/search.rs @@ -82,11 +82,11 @@ impl SearchOptions { options } - pub fn as_button(&self, active: bool) -> impl RenderOnce { + pub fn as_button(&self, active: bool) -> impl RenderOnce { ui::IconButton::new(0, self.icon()) .on_click({ let action = self.to_toggle_action(); - move |_: &mut V, cx| { + move |_, cx| { cx.dispatch_action(action.boxed_clone()); } }) @@ -95,10 +95,10 @@ impl SearchOptions { } } -fn toggle_replace_button(active: bool) -> impl RenderOnce { +fn toggle_replace_button(active: bool) -> impl RenderOnce { // todo: add toggle_replace button ui::IconButton::new(0, ui::Icon::Replace) - .on_click(|_: &mut V, cx| { + .on_click(|_, cx| { cx.dispatch_action(Box::new(ToggleReplace)); cx.notify(); }) @@ -106,12 +106,12 @@ fn toggle_replace_button(active: bool) -> impl RenderOnce { .when(active, |button| button.variant(ButtonVariant::Filled)) } -fn render_replace_button( +fn render_replace_button( action: impl Action + 'static + Send + Sync, icon: ui::Icon, -) -> impl RenderOnce { +) -> impl RenderOnce { // todo: add tooltip - ui::IconButton::new(0, icon).on_click(move |_: &mut V, cx| { + ui::IconButton::new(0, icon).on_click(move |_, cx| { cx.dispatch_action(action.boxed_clone()); }) } diff --git a/crates/search2/src/search_bar.rs b/crates/search2/src/search_bar.rs index ffb7c99e27725c533673a0d2d5835f9a6b90bee1..da097b43a66207b62fc914c1e11caf3c4eccd81e 100644 --- a/crates/search2/src/search_bar.rs +++ b/crates/search2/src/search_bar.rs @@ -1,15 +1,13 @@ -use std::sync::Arc; - -use gpui::{RenderOnce, ViewContext}; +use gpui::{MouseDownEvent, RenderOnce, WindowContext}; use ui::{Button, ButtonVariant, IconButton}; use crate::mode::SearchMode; -pub(super) fn render_nav_button( +pub(super) fn render_nav_button( icon: ui::Icon, _active: bool, - on_click: impl Fn(&mut V, &mut ViewContext) + 'static + Send + Sync, -) -> impl RenderOnce { + on_click: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static, +) -> impl RenderOnce { // let tooltip_style = cx.theme().tooltip.clone(); // let cursor_style = if active { // CursorStyle::PointingHand @@ -20,11 +18,11 @@ pub(super) fn render_nav_button( IconButton::new("search-nav-button", icon).on_click(on_click) } -pub(crate) fn render_search_mode_button( +pub(crate) fn render_search_mode_button( mode: SearchMode, is_active: bool, - on_click: impl Fn(&mut V, &mut ViewContext) + 'static + Send + Sync, -) -> Button { + on_click: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static, +) -> Button { let button_variant = if is_active { ButtonVariant::Filled } else { @@ -32,6 +30,6 @@ pub(crate) fn render_search_mode_button( }; Button::new(mode.label()) - .on_click(Arc::new(on_click)) + .on_click(on_click) .variant(button_variant) } diff --git a/crates/workspace2/src/toolbar.rs b/crates/workspace2/src/toolbar.rs index 82d5deaea1fe6d1168d024ff86dbf0cb124a3a70..298a7bee0587c45a8a736f15339b0b4756a9718e 100644 --- a/crates/workspace2/src/toolbar.rs +++ b/crates/workspace2/src/toolbar.rs @@ -79,7 +79,6 @@ impl Toolbar { impl Render for Toolbar { type Element = Div; - fn render(&mut self, cx: &mut ViewContext) -> Self::Element { //dbg!(&self.items.len()); v_stack()