From cc62945c6b1fc05e1268ab2c9ca2c7fb3f4dca28 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Wed, 3 May 2023 14:38:06 -0400 Subject: [PATCH 01/17] v0.85.x preview --- crates/zed/RELEASE_CHANNEL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/zed/RELEASE_CHANNEL b/crates/zed/RELEASE_CHANNEL index 90012116c0..4de2f126df 100644 --- a/crates/zed/RELEASE_CHANNEL +++ b/crates/zed/RELEASE_CHANNEL @@ -1 +1 @@ -dev \ No newline at end of file +preview \ No newline at end of file From 3407b16ec879ae12d2d4e15c88e6371db41e9fe5 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 4 May 2023 14:22:42 +0200 Subject: [PATCH 02/17] Merge pull request #2439 from zed-industries/fix-keystrokes-for-action Cache view's type id and keymap context into a separate map --- crates/collab_ui/src/contact_list.rs | 7 +- crates/context_menu/src/context_menu.rs | 7 +- crates/editor/src/editor.rs | 26 +-- crates/gpui/src/app.rs | 174 ++++++++++-------- crates/gpui/src/app/window.rs | 30 +-- .../gpui/src/keymap_matcher/keymap_context.rs | 5 + crates/picker/src/picker.rs | 7 +- crates/project_panel/src/project_panel.rs | 7 +- crates/terminal_view/src/terminal_view.rs | 35 ++-- crates/vim/src/vim.rs | 4 +- crates/workspace/src/pane.rs | 5 +- crates/workspace/src/workspace.rs | 5 - 12 files changed, 169 insertions(+), 143 deletions(-) diff --git a/crates/collab_ui/src/contact_list.rs b/crates/collab_ui/src/contact_list.rs index 87aa41b7a4..452867b8c4 100644 --- a/crates/collab_ui/src/contact_list.rs +++ b/crates/collab_ui/src/contact_list.rs @@ -1306,10 +1306,9 @@ impl View for ContactList { "ContactList" } - fn keymap_context(&self, _: &AppContext) -> KeymapContext { - let mut cx = Self::default_keymap_context(); - cx.add_identifier("menu"); - cx + fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) { + Self::reset_to_default_keymap_context(keymap); + keymap.add_identifier("menu"); } fn render(&mut self, cx: &mut ViewContext) -> AnyElement { diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index e0429bd01b..0a4cd59384 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -140,10 +140,9 @@ impl View for ContextMenu { "ContextMenu" } - fn keymap_context(&self, _: &AppContext) -> KeymapContext { - let mut cx = Self::default_keymap_context(); - cx.add_identifier("menu"); - cx + fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) { + Self::reset_to_default_keymap_context(keymap); + keymap.add_identifier("menu"); } fn render(&mut self, cx: &mut ViewContext) -> AnyElement { diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index be57596584..641ef4d133 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1425,13 +1425,19 @@ impl Editor { } } - pub fn set_keymap_context_layer(&mut self, context: KeymapContext) { + pub fn set_keymap_context_layer( + &mut self, + context: KeymapContext, + cx: &mut ViewContext, + ) { self.keymap_context_layers .insert(TypeId::of::(), context); + cx.notify(); } - pub fn remove_keymap_context_layer(&mut self) { + pub fn remove_keymap_context_layer(&mut self, cx: &mut ViewContext) { self.keymap_context_layers.remove(&TypeId::of::()); + cx.notify(); } pub fn set_input_enabled(&mut self, input_enabled: bool) { @@ -7157,28 +7163,26 @@ impl View for Editor { false } - fn keymap_context(&self, _: &AppContext) -> KeymapContext { - let mut context = Self::default_keymap_context(); + fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) { + Self::reset_to_default_keymap_context(keymap); let mode = match self.mode { EditorMode::SingleLine => "single_line", EditorMode::AutoHeight { .. } => "auto_height", EditorMode::Full => "full", }; - context.add_key("mode", mode); + keymap.add_key("mode", mode); if self.pending_rename.is_some() { - context.add_identifier("renaming"); + keymap.add_identifier("renaming"); } match self.context_menu.as_ref() { - Some(ContextMenu::Completions(_)) => context.add_identifier("showing_completions"), - Some(ContextMenu::CodeActions(_)) => context.add_identifier("showing_code_actions"), + Some(ContextMenu::Completions(_)) => keymap.add_identifier("showing_completions"), + Some(ContextMenu::CodeActions(_)) => keymap.add_identifier("showing_code_actions"), None => {} } for layer in self.keymap_context_layers.values() { - context.extend(layer); + keymap.extend(layer); } - - context } fn text_for_range(&self, range_utf16: Range, cx: &AppContext) -> Option { diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 4d84f7c070..caebc2714a 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -83,14 +83,15 @@ pub trait View: Entity + Sized { false } - fn keymap_context(&self, _: &AppContext) -> keymap_matcher::KeymapContext { - Self::default_keymap_context() + fn update_keymap_context(&self, keymap: &mut keymap_matcher::KeymapContext, _: &AppContext) { + Self::reset_to_default_keymap_context(keymap); } - fn default_keymap_context() -> keymap_matcher::KeymapContext { - let mut cx = keymap_matcher::KeymapContext::default(); - cx.add_identifier(Self::ui_name()); - cx + + fn reset_to_default_keymap_context(keymap: &mut keymap_matcher::KeymapContext) { + keymap.clear(); + keymap.add_identifier(Self::ui_name()); } + fn debug_json(&self, _: &AppContext) -> serde_json::Value { serde_json::Value::Null } @@ -440,6 +441,7 @@ type WindowShouldCloseSubscriptionCallback = Box b pub struct AppContext { models: HashMap>, views: HashMap<(usize, usize), Box>, + views_metadata: HashMap<(usize, usize), ViewMetadata>, pub(crate) parents: HashMap<(usize, usize), ParentId>, windows: HashMap, globals: HashMap>, @@ -502,6 +504,7 @@ impl AppContext { Self { models: Default::default(), views: Default::default(), + views_metadata: Default::default(), parents: Default::default(), windows: Default::default(), globals: Default::default(), @@ -727,9 +730,9 @@ impl AppContext { } pub fn view_type_id(&self, window_id: usize, view_id: usize) -> Option { - self.views + self.views_metadata .get(&(window_id, view_id)) - .map(|view| view.as_any().type_id()) + .map(|metadata| metadata.type_id) } pub fn active_labeled_tasks<'a>( @@ -1045,9 +1048,10 @@ impl AppContext { .read_window(window_id, |cx| { if let Some(focused_view_id) = cx.focused_view_id() { for view_id in cx.ancestors(focused_view_id) { - if let Some(view) = cx.views.get(&(window_id, view_id)) { - let view_type = view.as_any().type_id(); - if let Some(actions) = cx.actions.get(&view_type) { + if let Some(view_metadata) = + cx.views_metadata.get(&(window_id, view_id)) + { + if let Some(actions) = cx.actions.get(&view_metadata.type_id) { if actions.contains_key(&action_type) { return true; } @@ -1448,6 +1452,7 @@ impl AppContext { for (window_id, view_id) in dropped_views { self.subscriptions.remove(view_id); self.observations.remove(view_id); + self.views_metadata.remove(&(window_id, view_id)); let mut view = self.views.remove(&(window_id, view_id)).unwrap(); view.release(self); let change_focus_to = self.windows.get_mut(&window_id).and_then(|window| { @@ -1779,9 +1784,11 @@ impl AppContext { observed_window_id: usize, observed_view_id: usize, ) { - if self + let view_key = (observed_window_id, observed_view_id); + if let Some((view, mut view_metadata)) = self .views - .contains_key(&(observed_window_id, observed_view_id)) + .remove(&view_key) + .zip(self.views_metadata.remove(&view_key)) { if let Some(window) = self.windows.get_mut(&observed_window_id) { window @@ -1791,6 +1798,10 @@ impl AppContext { .insert(observed_view_id); } + view.update_keymap_context(&mut view_metadata.keymap_context, self); + self.views.insert(view_key, view); + self.views_metadata.insert(view_key, view_metadata); + let mut observations = self.observations.clone(); observations.emit(observed_view_id, |callback| callback(self)); } @@ -2037,6 +2048,11 @@ pub enum ParentId { Root, } +struct ViewMetadata { + type_id: TypeId, + keymap_context: KeymapContext, +} + #[derive(Default, Clone)] pub struct WindowInvalidation { pub updated: HashSet, @@ -2365,7 +2381,7 @@ pub trait AnyView { cx: &mut WindowContext, view_id: usize, ) -> bool; - fn keymap_context(&self, cx: &AppContext) -> KeymapContext; + fn update_keymap_context(&self, keymap: &mut KeymapContext, cx: &AppContext); fn debug_json(&self, cx: &WindowContext) -> serde_json::Value; fn text_for_range(&self, range: Range, cx: &WindowContext) -> Option; @@ -2437,11 +2453,10 @@ where cx.handle().into_any() } else { let focused_type = cx - .views + .views_metadata .get(&(cx.window_id, focused_id)) .unwrap() - .as_any() - .type_id(); + .type_id; AnyViewHandle::new( cx.window_id, focused_id, @@ -2458,11 +2473,10 @@ where cx.handle().into_any() } else { let blurred_type = cx - .views + .views_metadata .get(&(cx.window_id, blurred_id)) .unwrap() - .as_any() - .type_id(); + .type_id; AnyViewHandle::new( cx.window_id, blurred_id, @@ -2493,8 +2507,8 @@ where View::modifiers_changed(self, event, &mut cx) } - fn keymap_context(&self, cx: &AppContext) -> KeymapContext { - View::keymap_context(self, cx) + fn update_keymap_context(&self, keymap: &mut KeymapContext, cx: &AppContext) { + View::update_keymap_context(self, keymap, cx) } fn debug_json(&self, cx: &WindowContext) -> serde_json::Value { @@ -5559,8 +5573,8 @@ mod tests { "View" } - fn keymap_context(&self, _: &AppContext) -> KeymapContext { - self.keymap_context.clone() + fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) { + *keymap = self.keymap_context.clone(); } } @@ -5664,7 +5678,7 @@ mod tests { } #[crate::test(self)] - fn test_keystrokes_for_action(cx: &mut AppContext) { + fn test_keystrokes_for_action(cx: &mut TestAppContext) { actions!(test, [Action1, Action2, GlobalAction]); struct View1 {} @@ -5694,70 +5708,76 @@ mod tests { } } - let (window_id, view_1) = cx.add_window(Default::default(), |_| View1 {}); + let (_, view_1) = cx.add_window(|_| View1 {}); let view_2 = cx.add_view(&view_1, |cx| { cx.focus_self(); View2 {} }); - cx.add_action(|_: &mut View1, _: &Action1, _cx| {}); - cx.add_action(|_: &mut View2, _: &Action2, _cx| {}); - cx.add_global_action(|_: &GlobalAction, _| {}); + cx.update(|cx| { + cx.add_action(|_: &mut View1, _: &Action1, _cx| {}); + cx.add_action(|_: &mut View2, _: &Action2, _cx| {}); + cx.add_global_action(|_: &GlobalAction, _| {}); - cx.add_bindings(vec![ - Binding::new("a", Action1, Some("View1")), - Binding::new("b", Action2, Some("View1 > View2")), - Binding::new("c", GlobalAction, Some("View3")), // View 3 does not exist - ]); + cx.add_bindings(vec![ + Binding::new("a", Action1, Some("View1")), + Binding::new("b", Action2, Some("View1 > View2")), + Binding::new("c", GlobalAction, Some("View3")), // View 3 does not exist + ]); + }); - cx.update_window(window_id, |cx| { - // Sanity check - assert_eq!( - cx.keystrokes_for_action(view_1.id(), &Action1) - .unwrap() - .as_slice(), - &[Keystroke::parse("a").unwrap()] - ); - assert_eq!( - cx.keystrokes_for_action(view_2.id(), &Action2) - .unwrap() - .as_slice(), - &[Keystroke::parse("b").unwrap()] - ); + // Here we update the views to ensure that, even if they are on the stack, + // we can still retrieve keystrokes correctly. + view_1.update(cx, |_, cx| { + view_2.update(cx, |_, cx| { + // Sanity check + assert_eq!( + cx.keystrokes_for_action(view_1.id(), &Action1) + .unwrap() + .as_slice(), + &[Keystroke::parse("a").unwrap()] + ); + assert_eq!( + cx.keystrokes_for_action(view_2.id(), &Action2) + .unwrap() + .as_slice(), + &[Keystroke::parse("b").unwrap()] + ); - // The 'a' keystroke propagates up the view tree from view_2 - // to view_1. The action, Action1, is handled by view_1. - assert_eq!( - cx.keystrokes_for_action(view_2.id(), &Action1) - .unwrap() - .as_slice(), - &[Keystroke::parse("a").unwrap()] - ); + // The 'a' keystroke propagates up the view tree from view_2 + // to view_1. The action, Action1, is handled by view_1. + assert_eq!( + cx.keystrokes_for_action(view_2.id(), &Action1) + .unwrap() + .as_slice(), + &[Keystroke::parse("a").unwrap()] + ); - // Actions that are handled below the current view don't have bindings - assert_eq!(cx.keystrokes_for_action(view_1.id(), &Action2), None); + // Actions that are handled below the current view don't have bindings + assert_eq!(cx.keystrokes_for_action(view_1.id(), &Action2), None); - // Actions that are handled in other branches of the tree should not have a binding - assert_eq!(cx.keystrokes_for_action(view_2.id(), &GlobalAction), None); + // Actions that are handled in other branches of the tree should not have a binding + assert_eq!(cx.keystrokes_for_action(view_2.id(), &GlobalAction), None); - // Check that global actions do not have a binding, even if a binding does exist in another view - assert_eq!( - &available_actions(view_1.id(), cx), - &[ - ("test::Action1", vec![Keystroke::parse("a").unwrap()]), - ("test::GlobalAction", vec![]) - ], - ); + // Check that global actions do not have a binding, even if a binding does exist in another view + assert_eq!( + &available_actions(view_1.id(), cx), + &[ + ("test::Action1", vec![Keystroke::parse("a").unwrap()]), + ("test::GlobalAction", vec![]) + ], + ); - // Check that view 1 actions and bindings are available even when called from view 2 - assert_eq!( - &available_actions(view_2.id(), cx), - &[ - ("test::Action1", vec![Keystroke::parse("a").unwrap()]), - ("test::Action2", vec![Keystroke::parse("b").unwrap()]), - ("test::GlobalAction", vec![]), - ], - ); + // Check that view 1 actions and bindings are available even when called from view 2 + assert_eq!( + &available_actions(view_2.id(), cx), + &[ + ("test::Action1", vec![Keystroke::parse("a").unwrap()]), + ("test::Action2", vec![Keystroke::parse("b").unwrap()]), + ("test::GlobalAction", vec![]), + ], + ); + }); }); // Produces a list of actions and key bindings diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rs index 49befafbec..94c4df2385 100644 --- a/crates/gpui/src/app/window.rs +++ b/crates/gpui/src/app/window.rs @@ -2,7 +2,7 @@ use crate::{ elements::AnyRootElement, geometry::rect::RectF, json::ToJson, - keymap_matcher::{Binding, Keystroke, MatchResult}, + keymap_matcher::{Binding, KeymapContext, Keystroke, MatchResult}, platform::{ self, Appearance, CursorStyle, Event, KeyDownEvent, KeyUpEvent, ModifiersChangedEvent, MouseButton, MouseMovedEvent, PromptLevel, WindowBounds, @@ -34,7 +34,7 @@ use std::{ use util::ResultExt; use uuid::Uuid; -use super::Reference; +use super::{Reference, ViewMetadata}; pub struct Window { pub(crate) root_view: Option, @@ -369,13 +369,13 @@ impl<'a> WindowContext<'a> { let mut contexts = Vec::new(); let mut handler_depth = None; for (i, view_id) in self.ancestors(view_id).enumerate() { - if let Some(view) = self.views.get(&(window_id, view_id)) { - if let Some(actions) = self.actions.get(&view.as_any().type_id()) { + if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) { + if let Some(actions) = self.actions.get(&view_metadata.type_id) { if actions.contains_key(&action.as_any().type_id()) { handler_depth = Some(i); } } - contexts.push(view.keymap_context(self)); + contexts.push(view_metadata.keymap_context.clone()); } } @@ -406,10 +406,9 @@ impl<'a> WindowContext<'a> { let mut contexts = Vec::new(); let mut handler_depths_by_action_type = HashMap::::default(); for (depth, view_id) in self.ancestors(view_id).enumerate() { - if let Some(view) = self.views.get(&(window_id, view_id)) { - contexts.push(view.keymap_context(self)); - let view_type = view.as_any().type_id(); - if let Some(actions) = self.actions.get(&view_type) { + if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) { + contexts.push(view_metadata.keymap_context.clone()); + if let Some(actions) = self.actions.get(&view_metadata.type_id) { handler_depths_by_action_type.extend( actions .keys() @@ -458,9 +457,9 @@ impl<'a> WindowContext<'a> { let dispatch_path = self .ancestors(focused_view_id) .filter_map(|view_id| { - self.views + self.views_metadata .get(&(window_id, view_id)) - .map(|view| (view_id, view.keymap_context(self))) + .map(|view| (view_id, view.keymap_context.clone())) }) .collect(); @@ -1177,6 +1176,15 @@ impl<'a> WindowContext<'a> { self.parents.insert((window_id, view_id), parent_id); let mut cx = ViewContext::mutable(self, view_id); let handle = if let Some(view) = build_view(&mut cx) { + let mut keymap_context = KeymapContext::default(); + view.update_keymap_context(&mut keymap_context, cx.app_context()); + self.views_metadata.insert( + (window_id, view_id), + ViewMetadata { + type_id: TypeId::of::(), + keymap_context, + }, + ); self.views.insert((window_id, view_id), Box::new(view)); self.window .invalidation diff --git a/crates/gpui/src/keymap_matcher/keymap_context.rs b/crates/gpui/src/keymap_matcher/keymap_context.rs index bbf6bfc14b..b1a449edf3 100644 --- a/crates/gpui/src/keymap_matcher/keymap_context.rs +++ b/crates/gpui/src/keymap_matcher/keymap_context.rs @@ -17,6 +17,11 @@ impl KeymapContext { } } + pub fn clear(&mut self) { + self.set.clear(); + self.map.clear(); + } + pub fn extend(&mut self, other: &Self) { for v in &other.set { self.set.insert(v.clone()); diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 62ffd417fe..01749ccf84 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -126,10 +126,9 @@ impl View for Picker { .into_any_named("picker") } - fn keymap_context(&self, _: &AppContext) -> KeymapContext { - let mut cx = Self::default_keymap_context(); - cx.add_identifier("menu"); - cx + fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) { + Self::reset_to_default_keymap_context(keymap); + keymap.add_identifier("menu"); } fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 373417b167..ec80bd245a 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -1316,10 +1316,9 @@ impl View for ProjectPanel { } } - fn keymap_context(&self, _: &AppContext) -> KeymapContext { - let mut cx = Self::default_keymap_context(); - cx.add_identifier("menu"); - cx + fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) { + Self::reset_to_default_keymap_context(keymap); + keymap.add_identifier("menu"); } } diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 5e04fc9825..3fcbf39887 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -446,11 +446,11 @@ impl View for TerminalView { }); } - fn keymap_context(&self, cx: &gpui::AppContext) -> KeymapContext { - let mut context = Self::default_keymap_context(); + fn update_keymap_context(&self, keymap: &mut KeymapContext, cx: &gpui::AppContext) { + Self::reset_to_default_keymap_context(keymap); let mode = self.terminal.read(cx).last_content.mode; - context.add_key( + keymap.add_key( "screen", if mode.contains(TermMode::ALT_SCREEN) { "alt" @@ -460,40 +460,40 @@ impl View for TerminalView { ); if mode.contains(TermMode::APP_CURSOR) { - context.add_identifier("DECCKM"); + keymap.add_identifier("DECCKM"); } if mode.contains(TermMode::APP_KEYPAD) { - context.add_identifier("DECPAM"); + keymap.add_identifier("DECPAM"); } else { - context.add_identifier("DECPNM"); + keymap.add_identifier("DECPNM"); } if mode.contains(TermMode::SHOW_CURSOR) { - context.add_identifier("DECTCEM"); + keymap.add_identifier("DECTCEM"); } if mode.contains(TermMode::LINE_WRAP) { - context.add_identifier("DECAWM"); + keymap.add_identifier("DECAWM"); } if mode.contains(TermMode::ORIGIN) { - context.add_identifier("DECOM"); + keymap.add_identifier("DECOM"); } if mode.contains(TermMode::INSERT) { - context.add_identifier("IRM"); + keymap.add_identifier("IRM"); } //LNM is apparently the name for this. https://vt100.net/docs/vt510-rm/LNM.html if mode.contains(TermMode::LINE_FEED_NEW_LINE) { - context.add_identifier("LNM"); + keymap.add_identifier("LNM"); } if mode.contains(TermMode::FOCUS_IN_OUT) { - context.add_identifier("report_focus"); + keymap.add_identifier("report_focus"); } if mode.contains(TermMode::ALTERNATE_SCROLL) { - context.add_identifier("alternate_scroll"); + keymap.add_identifier("alternate_scroll"); } if mode.contains(TermMode::BRACKETED_PASTE) { - context.add_identifier("bracketed_paste"); + keymap.add_identifier("bracketed_paste"); } if mode.intersects(TermMode::MOUSE_MODE) { - context.add_identifier("any_mouse_reporting"); + keymap.add_identifier("any_mouse_reporting"); } { let mouse_reporting = if mode.contains(TermMode::MOUSE_REPORT_CLICK) { @@ -505,7 +505,7 @@ impl View for TerminalView { } else { "off" }; - context.add_key("mouse_reporting", mouse_reporting); + keymap.add_key("mouse_reporting", mouse_reporting); } { let format = if mode.contains(TermMode::SGR_MOUSE) { @@ -515,9 +515,8 @@ impl View for TerminalView { } else { "normal" }; - context.add_key("mouse_format", format); + keymap.add_key("mouse_format", format); } - context } } diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 7ce925944c..a0a12210ec 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -309,7 +309,7 @@ impl Vim { editor.set_input_enabled(!state.vim_controlled()); editor.selections.line_mode = matches!(state.mode, Mode::Visual { line: true }); let context_layer = state.keymap_context_layer(); - editor.set_keymap_context_layer::(context_layer); + editor.set_keymap_context_layer::(context_layer, cx); } else { Self::unhook_vim_settings(editor, cx); } @@ -321,7 +321,7 @@ impl Vim { editor.set_clip_at_line_ends(false, cx); editor.set_input_enabled(true); editor.selections.line_mode = false; - editor.remove_keymap_context_layer::(); + editor.remove_keymap_context_layer::(cx); } } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 8bd42fed04..3d1e477941 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1831,12 +1831,11 @@ impl View for Pane { }); } - fn keymap_context(&self, _: &AppContext) -> KeymapContext { - let mut keymap = Self::default_keymap_context(); + fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) { + Self::reset_to_default_keymap_context(keymap); if self.docked.is_some() { keymap.add_identifier("docked"); } - keymap } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index bb2629862d..e1007043dc 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -37,7 +37,6 @@ use gpui::{ vector::{vec2f, Vector2F}, }, impl_actions, - keymap_matcher::KeymapContext, platform::{ CursorStyle, MouseButton, PathPromptOptions, Platform, PromptLevel, WindowBounds, WindowOptions, @@ -2809,10 +2808,6 @@ impl View for Workspace { } } } - - fn keymap_context(&self, _: &AppContext) -> KeymapContext { - Self::default_keymap_context() - } } impl ViewId { From e23ca8d20ebc2b0daf09f19cc47c108575872227 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 4 May 2023 14:56:43 +0200 Subject: [PATCH 03/17] Merge pull request #2440 from zed-industries/fix-navigate-to-definitions-panic Fix panic when opening multiple definitions in a multibuffer --- crates/editor/src/editor.rs | 44 +++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 641ef4d133..8771387cb7 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5680,28 +5680,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) + }); + }); } } From fcbdfe849f0bc7ea695d65b061229bc67ea5ef32 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 4 May 2023 15:00:19 +0200 Subject: [PATCH 04/17] Merge pull request #2442 from zed-industries/filter-vim-commands Filter out vim commands when vim mode is disabled --- crates/vim/src/vim.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index a0a12210ec..cc686f851f 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) }); From dc8f348cdbd022b9033123d1f0b1a3d1e5bf5db3 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 4 May 2023 16:24:51 +0200 Subject: [PATCH 05/17] Merge pull request #2443 from zed-industries/fix-vim-mode-rename Avoid calling `update_window` twice in `blurred` event handler --- crates/vim/src/editor_events.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/vim/src/editor_events.rs b/crates/vim/src/editor_events.rs index 4324bc6054..a11f1cc182 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)) }); }); } From 96dffc06e7051edbbdac5d71503fe2ab8b032f4c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 4 May 2023 17:14:40 +0200 Subject: [PATCH 06/17] Merge pull request #2444 from zed-industries/fix-clicking-sidebar-buttons Use `Workspace::toggle_sidebar_item` when clicking on sidebar button --- crates/workspace/src/sidebar.rs | 28 +++++++++++++++++++++------- crates/workspace/src/workspace.rs | 5 +++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/crates/workspace/src/sidebar.rs b/crates/workspace/src/sidebar.rs index 2b114d83ec..ed629745a8 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 e1007043dc..cbac091128 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -583,10 +583,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); From 08e5e5a43d8b749f0f1078db7d351cb9f18ec771 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 4 May 2023 17:15:30 +0200 Subject: [PATCH 07/17] zed 0.85.1 --- Cargo.lock | 2 +- crates/zed/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2b29c7aeb..cd4c0cbe17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8546,7 +8546,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zed" -version = "0.85.0" +version = "0.85.1" dependencies = [ "activity_indicator", "anyhow", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 7157404640..586227b8a9 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -3,7 +3,7 @@ authors = ["Nathan Sobo "] description = "The fast, collaborative code editor." edition = "2021" name = "zed" -version = "0.85.0" +version = "0.85.1" publish = false [lib] From 41ef9cc27924ecda4d3faa5e379a9f0843ba7825 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Thu, 4 May 2023 17:15:09 -0400 Subject: [PATCH 08/17] Merge pull request #2447 from zed-industries/fix-auto-update Do not use post_json() to auto update --- crates/auto_update/src/auto_update.rs | 2 +- crates/client/src/telemetry.rs | 6 +++--- crates/util/src/http.rs | 6 ------ 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index abf95ff45a..68d3776e1c 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -273,7 +273,7 @@ impl AutoUpdater { telemetry, })?); - let mut response = client.post_json(&release.url, request_body, true).await?; + let mut response = client.get(&release.url, request_body, true).await?; smol::io::copy(response.body_mut(), &mut dmg_file).await?; log::info!("downloaded update. path:{:?}", dmg_path); diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 5dfb6595d1..7151dcd7bb 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -270,7 +270,7 @@ impl Telemetry { }])?; this.http_client - .post_json(MIXPANEL_ENGAGE_URL, json_bytes.into(), false) + .post_json(MIXPANEL_ENGAGE_URL, json_bytes.into()) .await?; anyhow::Ok(()) } @@ -404,7 +404,7 @@ impl Telemetry { json_bytes.clear(); serde_json::to_writer(&mut json_bytes, &events)?; this.http_client - .post_json(MIXPANEL_EVENTS_URL, json_bytes.into(), false) + .post_json(MIXPANEL_EVENTS_URL, json_bytes.into()) .await?; anyhow::Ok(()) } @@ -454,7 +454,7 @@ impl Telemetry { } this.http_client - .post_json(CLICKHOUSE_EVENTS_URL.as_str(), json_bytes.into(), false) + .post_json(CLICKHOUSE_EVENTS_URL.as_str(), json_bytes.into()) .await?; anyhow::Ok(()) } diff --git a/crates/util/src/http.rs b/crates/util/src/http.rs index e7f39552b0..e29768a53e 100644 --- a/crates/util/src/http.rs +++ b/crates/util/src/http.rs @@ -40,14 +40,8 @@ pub trait HttpClient: Send + Sync { &'a self, uri: &str, body: AsyncBody, - follow_redirects: bool, ) -> BoxFuture<'a, Result, Error>> { let request = isahc::Request::builder() - .redirect_policy(if follow_redirects { - RedirectPolicy::Follow - } else { - RedirectPolicy::None - }) .method(Method::POST) .uri(uri) .header("Content-Type", "application/json") From 8ff3f6569d84d3ec832412726f3aa84b7c8f8139 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 4 May 2023 16:52:04 -0400 Subject: [PATCH 09/17] Merge pull request #2446 from zed-industries/fix-copilot-logged-out Fix copilot stuck in logged out state --- crates/copilot/src/copilot.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index ea25355065..a30ae6961e 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -461,14 +461,12 @@ impl Copilot { pub fn sign_in(&mut self, cx: &mut ModelContext) -> Task> { if let CopilotServer::Running(server) = &mut self.server { let task = match &server.sign_in_status { - SignInStatus::Authorized { .. } | SignInStatus::Unauthorized { .. } => { - Task::ready(Ok(())).shared() - } + SignInStatus::Authorized { .. } => Task::ready(Ok(())).shared(), SignInStatus::SigningIn { task, .. } => { cx.notify(); task.clone() } - SignInStatus::SignedOut => { + SignInStatus::SignedOut | SignInStatus::Unauthorized { .. } => { let lsp = server.lsp.clone(); let task = cx .spawn(|this, mut cx| async move { From 5faceaf6590030c6da676e9cae40bd4b7cb6841d Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 4 May 2023 17:14:40 +0200 Subject: [PATCH 10/17] Merge pull request #2444 from zed-industries/fix-clicking-sidebar-buttons Use `Workspace::toggle_sidebar_item` when clicking on sidebar button From 2fcf186b17751c803358c5e0f5bd7249d812c5b8 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Thu, 4 May 2023 17:29:26 -0400 Subject: [PATCH 11/17] zed 0.85.2 --- Cargo.lock | 2 +- crates/zed/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd4c0cbe17..74a3d854a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8546,7 +8546,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zed" -version = "0.85.1" +version = "0.85.2" dependencies = [ "activity_indicator", "anyhow", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 586227b8a9..a298cef3bd 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -3,7 +3,7 @@ authors = ["Nathan Sobo "] description = "The fast, collaborative code editor." edition = "2021" name = "zed" -version = "0.85.1" +version = "0.85.2" publish = false [lib] From 203574b97526a636bff44aadf4662d54b33a8e5f Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 8 May 2023 13:59:57 -0400 Subject: [PATCH 12/17] Merge pull request #2453 from zed-industries/fix-click-fallthrough Fixed clicks falling through the modal terminal --- crates/gpui/src/scene/mouse_region.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/gpui/src/scene/mouse_region.rs b/crates/gpui/src/scene/mouse_region.rs index 258583124f..0efc794148 100644 --- a/crates/gpui/src/scene/mouse_region.rs +++ b/crates/gpui/src/scene/mouse_region.rs @@ -223,41 +223,41 @@ impl HandlerSet { set.insert( HandlerKey::new(MouseEvent::move_disc(), None), - SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), + SmallVec::from_buf([Rc::new(|_, _, _, _| true)]), ); set.insert( HandlerKey::new(MouseEvent::hover_disc(), None), - SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), + SmallVec::from_buf([Rc::new(|_, _, _, _| true)]), ); for button in MouseButton::all() { set.insert( HandlerKey::new(MouseEvent::drag_disc(), Some(button)), - SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), + SmallVec::from_buf([Rc::new(|_, _, _, _| true)]), ); set.insert( HandlerKey::new(MouseEvent::down_disc(), Some(button)), - SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), + SmallVec::from_buf([Rc::new(|_, _, _, _| true)]), ); set.insert( HandlerKey::new(MouseEvent::up_disc(), Some(button)), - SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), + SmallVec::from_buf([Rc::new(|_, _, _, _| true)]), ); set.insert( HandlerKey::new(MouseEvent::click_disc(), Some(button)), - SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), + SmallVec::from_buf([Rc::new(|_, _, _, _| true)]), ); set.insert( HandlerKey::new(MouseEvent::down_out_disc(), Some(button)), - SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), + SmallVec::from_buf([Rc::new(|_, _, _, _| true)]), ); set.insert( HandlerKey::new(MouseEvent::up_out_disc(), Some(button)), - SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), + SmallVec::from_buf([Rc::new(|_, _, _, _| true)]), ); } set.insert( HandlerKey::new(MouseEvent::scroll_wheel_disc(), None), - SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), + SmallVec::from_buf([Rc::new(|_, _, _, _| true)]), ); HandlerSet { set } From 36590cf22df82b0c557ee51dd13ff4d7922eaa2d Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 8 May 2023 11:48:41 -0700 Subject: [PATCH 13/17] zed 0.85.3 --- Cargo.lock | 2 +- crates/zed/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74a3d854a7..2523d85bf6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8546,7 +8546,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zed" -version = "0.85.2" +version = "0.85.3" dependencies = [ "activity_indicator", "anyhow", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index a298cef3bd..6c62e54fa6 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -3,7 +3,7 @@ authors = ["Nathan Sobo "] description = "The fast, collaborative code editor." edition = "2021" name = "zed" -version = "0.85.2" +version = "0.85.3" publish = false [lib] From fa6e8c9bfc6b7de9f85e89e3fd9cd1d75d38cb52 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 10 May 2023 09:24:23 +0200 Subject: [PATCH 14/17] Merge pull request #2458 from zed-industries/fix-context-menu-click Always dismiss context menu on click --- crates/context_menu/src/context_menu.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index 0a4cd59384..5e326c3216 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -126,7 +126,6 @@ pub struct ContextMenu { selected_index: Option, visible: bool, previously_focused_view_id: Option, - clicked: bool, parent_view_id: usize, _actions_observation: Subscription, } @@ -189,7 +188,6 @@ impl ContextMenu { selected_index: Default::default(), visible: Default::default(), previously_focused_view_id: Default::default(), - clicked: false, parent_view_id, _actions_observation: cx.observe_actions(Self::action_dispatched), } @@ -205,18 +203,14 @@ impl ContextMenu { .iter() .position(|item| item.action_id() == Some(action_id)) { - if self.clicked { - self.cancel(&Default::default(), cx); - } else { - self.selected_index = Some(ix); - cx.notify(); - cx.spawn(|this, mut cx| async move { - cx.background().timer(Duration::from_millis(50)).await; - this.update(&mut cx, |this, cx| this.cancel(&Default::default(), cx))?; - anyhow::Ok(()) - }) - .detach_and_log_err(cx); - } + self.selected_index = Some(ix); + cx.notify(); + cx.spawn(|this, mut cx| async move { + cx.background().timer(Duration::from_millis(50)).await; + this.update(&mut cx, |this, cx| this.cancel(&Default::default(), cx))?; + anyhow::Ok(()) + }) + .detach_and_log_err(cx); } } @@ -256,7 +250,6 @@ impl ContextMenu { self.items.clear(); self.visible = false; self.selected_index.take(); - self.clicked = false; cx.notify(); } @@ -456,7 +449,7 @@ impl ContextMenu { .on_up(MouseButton::Left, |_, _, _| {}) // Capture these events .on_down(MouseButton::Left, |_, _, _| {}) // Capture these events .on_click(MouseButton::Left, move |_, menu, cx| { - menu.clicked = true; + menu.cancel(&Default::default(), cx); let window_id = cx.window_id(); match &action { ContextMenuItemAction::Action(action) => { From 633ad71cdac62110351e93331734ff7d7485aed0 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Wed, 10 May 2023 16:46:51 -0400 Subject: [PATCH 15/17] v0.85.x stable --- crates/zed/RELEASE_CHANNEL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/zed/RELEASE_CHANNEL b/crates/zed/RELEASE_CHANNEL index 4de2f126df..870bbe4e50 100644 --- a/crates/zed/RELEASE_CHANNEL +++ b/crates/zed/RELEASE_CHANNEL @@ -1 +1 @@ -preview \ No newline at end of file +stable \ No newline at end of file From 01d9d8b6dec1e86a6be2824b1863721f874c00ec Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Thu, 11 May 2023 11:37:34 -0400 Subject: [PATCH 16/17] Revert "More keybindings in macOs modals with buttons" This reverts commit 1398a1206299cbaf5e14b9de30d2fbfe83f04334. --- crates/gpui/src/platform/mac/window.rs | 39 ++------------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index bcff08d005..d96f9bc4ae 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -699,31 +699,6 @@ impl platform::Window for Window { msg: &str, answers: &[&str], ) -> oneshot::Receiver { - // macOs applies overrides to modal window buttons after they are added. - // Two most important for this logic are: - // * Buttons with "Cancel" title will be displayed as the last buttons in the modal - // * Last button added to the modal via `addButtonWithTitle` stays focused - // * Focused buttons react on "space"/" " keypresses - // * Usage of `keyEquivalent`, `makeFirstResponder` or `setInitialFirstResponder` does not change the focus - // - // See also https://developer.apple.com/documentation/appkit/nsalert/1524532-addbuttonwithtitle#discussion - // ``` - // By default, the first button has a key equivalent of Return, - // any button with a title of “Cancel” has a key equivalent of Escape, - // and any button with the title “Don’t Save” has a key equivalent of Command-D (but only if it’s not the first button). - // ``` - // - // To avoid situations when the last element added is "Cancel" and it gets the focus - // (hence stealing both ESC and Space shortcuts), we find and add one non-Cancel button - // last, so it gets focus and a Space shortcut. - // This way, "Save this file? Yes/No/Cancel"-ish modals will get all three buttons mapped with a key. - let latest_non_cancel_label = answers - .iter() - .enumerate() - .rev() - .find(|(_, &label)| label != "Cancel") - .filter(|&(label_index, _)| label_index > 0); - unsafe { let alert: id = msg_send![class!(NSAlert), alloc]; let alert: id = msg_send![alert, init]; @@ -734,20 +709,10 @@ impl platform::Window for Window { }; let _: () = msg_send![alert, setAlertStyle: alert_style]; let _: () = msg_send![alert, setMessageText: ns_string(msg)]; - - for (ix, answer) in answers - .iter() - .enumerate() - .filter(|&(ix, _)| Some(ix) != latest_non_cancel_label.map(|(ix, _)| ix)) - { + for (ix, answer) in answers.iter().enumerate() { let button: id = msg_send![alert, addButtonWithTitle: ns_string(answer)]; let _: () = msg_send![button, setTag: ix as NSInteger]; } - if let Some((ix, answer)) = latest_non_cancel_label { - let button: id = msg_send![alert, addButtonWithTitle: ns_string(answer)]; - let _: () = msg_send![button, setTag: ix as NSInteger]; - } - let (done_tx, done_rx) = oneshot::channel(); let done_tx = Cell::new(Some(done_tx)); let block = ConcreteBlock::new(move |answer: NSInteger| { @@ -755,7 +720,7 @@ impl platform::Window for Window { let _ = postage::sink::Sink::try_send(&mut done_tx, answer.try_into().unwrap()); } }); - + let block = block.copy(); let native_window = self.0.borrow().native_window; self.0 .borrow() From 5cda0ec38ea4db9644a690de98986040056f6c29 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Thu, 11 May 2023 11:41:49 -0400 Subject: [PATCH 17/17] zed 0.85.4 --- Cargo.lock | 2 +- crates/zed/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2523d85bf6..77d2958b3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8546,7 +8546,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zed" -version = "0.85.3" +version = "0.85.4" dependencies = [ "activity_indicator", "anyhow", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 6c62e54fa6..b2f61cdf1e 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -3,7 +3,7 @@ authors = ["Nathan Sobo "] description = "The fast, collaborative code editor." edition = "2021" name = "zed" -version = "0.85.3" +version = "0.85.4" publish = false [lib]