Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Brave new world awaits
Piotr Osiewicz3e329861f9bd
diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rsindex 123b53c9866..3674baf3569 100644--- a/crates/search2/src/buffer_search.rs+++ b/crates/search2/src/buffer_search.rs@@ -63,8 +63,8 @@ pub struct BufferSearchBar {impl EventEmitter<Event> for BufferSearchBar {}impl EventEmitter<workspace::ToolbarItemEvent> for BufferSearchBar {}-impl Render<Self> for BufferSearchBar {- type Element = Div<Self>;+impl Render for BufferSearchBar {+ type Element = Div;fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {// let query_container_style = if self.query_contains_error {// theme.search.invalid_editor@@ -131,9 +131,13 @@ impl Render<Self> 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<Self> 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::<Self>(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::<Self>(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<Self> {+ 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<Self>) {@@ -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.rsindex c138c49d342..12152701bc6 100644--- a/crates/search2/src/search.rs+++ b/crates/search2/src/search.rs@@ -82,11 +82,11 @@ impl SearchOptions {options}- pub fn as_button<V: 'static>(&self, active: bool) -> impl RenderOnce<V> {+ 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<V: 'static>(active: bool) -> impl RenderOnce<V> {+fn toggle_replace_button(active: bool) -> impl RenderOnce {// todo: add toggle_replace buttonui::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<V: 'static>(active: bool) -> impl RenderOnce<V> {.when(active, |button| button.variant(ButtonVariant::Filled))}-fn render_replace_button<V: 'static>(+fn render_replace_button(action: impl Action + 'static + Send + Sync,icon: ui::Icon,-) -> impl RenderOnce<V> {+) -> 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.rsindex ffb7c99e277..da097b43a66 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<V: 'static>(+pub(super) fn render_nav_button(icon: ui::Icon,_active: bool,- on_click: impl Fn(&mut V, &mut ViewContext<V>) + 'static + Send + Sync,-) -> impl RenderOnce<V> {+ 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<V: 'static>(IconButton::new("search-nav-button", icon).on_click(on_click)}-pub(crate) fn render_search_mode_button<V: 'static>(+pub(crate) fn render_search_mode_button(mode: SearchMode,is_active: bool,- on_click: impl Fn(&mut V, &mut ViewContext<V>) + 'static + Send + Sync,-) -> Button<V> {+ 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<V: 'static>(};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.rsindex 82d5deaea1f..298a7bee058 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>) -> Self::Element {//dbg!(&self.items.len());v_stack()