diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 0bab846fad659adc75f8fec686179e36b8cba8c2..4efcde47cce2753dd902191351d0ddcbf25fcb1b 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5682,28 +5682,30 @@ impl Editor { } } else if !definitions.is_empty() { let replica_id = self.replica_id(cx); - let title = definitions - .iter() - .find(|definition| definition.origin.is_some()) - .and_then(|definition| { - definition.origin.as_ref().map(|origin| { - let buffer = origin.buffer.read(cx); - format!( - "Definitions for {}", - buffer - .text_for_range(origin.range.clone()) - .collect::() - ) + cx.window_context().defer(move |cx| { + let title = definitions + .iter() + .find(|definition| definition.origin.is_some()) + .and_then(|definition| { + definition.origin.as_ref().map(|origin| { + let buffer = origin.buffer.read(cx); + format!( + "Definitions for {}", + buffer + .text_for_range(origin.range.clone()) + .collect::() + ) + }) }) - }) - .unwrap_or("Definitions".to_owned()); - let locations = definitions - .into_iter() - .map(|definition| definition.target) - .collect(); - workspace.update(cx, |workspace, cx| { - Self::open_locations_in_multibuffer(workspace, locations, replica_id, title, cx) - }) + .unwrap_or("Definitions".to_owned()); + let locations = definitions + .into_iter() + .map(|definition| definition.target) + .collect(); + workspace.update(cx, |workspace, cx| { + Self::open_locations_in_multibuffer(workspace, locations, replica_id, title, cx) + }); + }); } } diff --git a/crates/vim/src/editor_events.rs b/crates/vim/src/editor_events.rs index 4324bc6054fde65c9384d900d14b1cfce046c310..a11f1cc182c64610ff588d46b51b142563b1abd7 100644 --- a/crates/vim/src/editor_events.rs +++ b/crates/vim/src/editor_events.rs @@ -35,9 +35,7 @@ fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) { } } - cx.update_window(editor.window_id(), |cx| { - editor.update(cx, |editor, cx| Vim::unhook_vim_settings(editor, cx)) - }); + editor.update(cx, |editor, cx| Vim::unhook_vim_settings(editor, cx)) }); }); } diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index a0a12210ec36d73a6fd468331622231f2b7802c0..cc686f851f21c7019c76a43840cea70a8d6f32de 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -84,7 +84,12 @@ pub fn init(cx: &mut AppContext) { Vim::active_editor_input_ignored("\n".into(), cx) }); - // Any time settings change, update vim mode to match. + // Any time settings change, update vim mode to match. The Vim struct + // will be initialized as disabled by default, so we filter its commands + // out when starting up. + cx.update_default_global::(|filter, _| { + filter.filtered_namespaces.insert("vim"); + }); cx.update_default_global(|vim: &mut Vim, cx: &mut AppContext| { vim.set_enabled(cx.global::().vim_mode, cx) }); diff --git a/crates/workspace/src/sidebar.rs b/crates/workspace/src/sidebar.rs index f37bd6da5f248a3a3a942482b2647e3790dcdfe6..6463ab7d24b9ea6e44ababa2c3768dc7d36b663a 100644 --- a/crates/workspace/src/sidebar.rs +++ b/crates/workspace/src/sidebar.rs @@ -1,7 +1,7 @@ -use crate::StatusItemView; +use crate::{StatusItemView, Workspace}; use gpui::{ elements::*, impl_actions, platform::CursorStyle, platform::MouseButton, AnyViewHandle, - AppContext, Entity, Subscription, View, ViewContext, ViewHandle, WindowContext, + AppContext, Entity, Subscription, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext, }; use serde::Deserialize; use settings::Settings; @@ -84,6 +84,7 @@ struct Item { pub struct SidebarButtons { sidebar: ViewHandle, + workspace: WeakViewHandle, } #[derive(Clone, Debug, Deserialize, PartialEq)] @@ -210,9 +211,13 @@ impl View for Sidebar { } impl SidebarButtons { - pub fn new(sidebar: ViewHandle, cx: &mut ViewContext) -> Self { + pub fn new( + sidebar: ViewHandle, + workspace: WeakViewHandle, + cx: &mut ViewContext, + ) -> Self { cx.observe(&sidebar, |_, _, cx| cx.notify()).detach(); - Self { sidebar } + Self { sidebar, workspace } } } @@ -279,9 +284,18 @@ impl View for SidebarButtons { .with_style(style.container) }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(MouseButton::Left, move |_, this, cx| { - this.sidebar - .update(cx, |sidebar, cx| sidebar.toggle_item(ix, cx)); + .on_click(MouseButton::Left, { + let action = action.clone(); + move |_, this, cx| { + if let Some(workspace) = this.workspace.upgrade(cx) { + let action = action.clone(); + cx.window_context().defer(move |cx| { + workspace.update(cx, |workspace, cx| { + workspace.toggle_sidebar_item(&action, cx) + }); + }); + } + } }) .with_tooltip::( ix, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 6b0eaf04a82ee04dd1ed288db71fe8773b975bcb..d69484caa7727b4ced8828800fb438b1c8417cb7 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -579,10 +579,11 @@ impl Workspace { let left_sidebar = cx.add_view(|_| Sidebar::new(SidebarSide::Left)); let right_sidebar = cx.add_view(|_| Sidebar::new(SidebarSide::Right)); - let left_sidebar_buttons = cx.add_view(|cx| SidebarButtons::new(left_sidebar.clone(), cx)); + let left_sidebar_buttons = + cx.add_view(|cx| SidebarButtons::new(left_sidebar.clone(), weak_handle.clone(), cx)); let toggle_dock = cx.add_view(|cx| ToggleDockButton::new(handle, cx)); let right_sidebar_buttons = - cx.add_view(|cx| SidebarButtons::new(right_sidebar.clone(), cx)); + cx.add_view(|cx| SidebarButtons::new(right_sidebar.clone(), weak_handle.clone(), cx)); let status_bar = cx.add_view(|cx| { let mut status_bar = StatusBar::new(¢er_pane.clone(), cx); status_bar.add_left_item(left_sidebar_buttons, cx);