From 84f98f13c47933eb584ebbfcd66dbb16d11aaf63 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 30 May 2023 11:52:14 -0700 Subject: [PATCH 1/9] Seperate open and zoom bits conceptually for new panels co-authored-by: max --- crates/workspace/src/dock.rs | 22 +++-- crates/workspace/src/workspace.rs | 140 +++++++++++++++++++++++++----- 2 files changed, 131 insertions(+), 31 deletions(-) diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 73d4f79399..fbfcbad817 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -180,7 +180,7 @@ impl Dock { } pub fn has_focus(&self, cx: &WindowContext) -> bool { - self.active_panel() + self.visible_panel() .map_or(false, |panel| panel.has_focus(cx)) } @@ -259,7 +259,7 @@ impl Dock { cx.focus(&panel); } } else if T::should_close_on_event(event) - && this.active_panel().map_or(false, |p| p.id() == panel.id()) + && this.visible_panel().map_or(false, |p| p.id() == panel.id()) { this.set_open(false, cx); } @@ -315,12 +315,16 @@ impl Dock { } } - pub fn active_panel(&self) -> Option<&Rc> { - let entry = self.active_entry()?; + pub fn visible_panel(&self) -> Option<&Rc> { + let entry = self.visible_entry()?; Some(&entry.panel) } - fn active_entry(&self) -> Option<&PanelEntry> { + pub fn active_panel(&self) -> Option<&Rc> { + Some(&self.panel_entries.get(self.active_panel_index)?.panel) + } + + fn visible_entry(&self) -> Option<&PanelEntry> { if self.is_open { self.panel_entries.get(self.active_panel_index) } else { @@ -329,7 +333,7 @@ impl Dock { } pub fn zoomed_panel(&self, cx: &WindowContext) -> Option> { - let entry = self.active_entry()?; + let entry = self.visible_entry()?; if entry.panel.is_zoomed(cx) { Some(entry.panel.clone()) } else { @@ -362,7 +366,7 @@ impl Dock { } pub fn render_placeholder(&self, cx: &WindowContext) -> AnyElement { - if let Some(active_entry) = self.active_entry() { + if let Some(active_entry) = self.visible_entry() { Empty::new() .into_any() .contained() @@ -399,7 +403,7 @@ impl View for Dock { } fn render(&mut self, cx: &mut ViewContext) -> AnyElement { - if let Some(active_entry) = self.active_entry() { + if let Some(active_entry) = self.visible_entry() { let style = self.style(cx); ChildView::new(active_entry.panel.as_any(), cx) .contained() @@ -417,7 +421,7 @@ impl View for Dock { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { - if let Some(active_entry) = self.active_entry() { + if let Some(active_entry) = self.visible_entry() { cx.focus(active_entry.panel.as_any()); } else { cx.focus_parent(); diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 8afad46ea1..6309b1d01f 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -901,7 +901,7 @@ impl Workspace { was_visible = dock.is_open() && dock - .active_panel() + .visible_panel() .map_or(false, |active_panel| active_panel.id() == panel.id()); dock.remove_panel(&panel, cx); }); @@ -1636,7 +1636,7 @@ impl Workspace { } else { dock.set_open(true, cx); dock.activate_panel(panel_index, cx); - dock.active_panel().cloned() + dock.visible_panel().cloned() } }); @@ -1658,17 +1658,27 @@ impl Workspace { pub fn toggle_panel_focus(&mut self, cx: &mut ViewContext) { for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] { if let Some(panel_index) = dock.read(cx).panel_index_for_type::() { - let active_item = dock.update(cx, |dock, cx| { - dock.set_open(true, cx); + let focus_center = dock.update(cx, |dock, cx| { dock.activate_panel(panel_index, cx); - dock.active_panel().cloned() - }); - if let Some(active_item) = active_item { - if active_item.has_focus(cx) { - cx.focus_self(); + + if let Some(panel) = dock.active_panel().cloned() { + if panel.has_focus(cx) { + if panel.is_zoomed(cx) { + dock.set_open(false, cx); + } + true + } else { + dock.set_open(true, cx); + cx.focus(panel.as_any()); + false + } } else { - cx.focus(active_item.as_any()); + false } + }); + + if focus_center { + cx.focus_self(); } self.serialize_workspace(cx); @@ -2835,7 +2845,7 @@ impl Workspace { fn build_serialized_docks(this: &Workspace, cx: &AppContext) -> DockStructure { let left_dock = this.left_dock.read(cx); let left_visible = left_dock.is_open(); - let left_active_panel = left_dock.active_panel().and_then(|panel| { + let left_active_panel = left_dock.visible_panel().and_then(|panel| { Some( cx.view_ui_name(panel.as_any().window_id(), panel.id())? .to_string(), @@ -2844,7 +2854,7 @@ impl Workspace { let right_dock = this.right_dock.read(cx); let right_visible = right_dock.is_open(); - let right_active_panel = right_dock.active_panel().and_then(|panel| { + let right_active_panel = right_dock.visible_panel().and_then(|panel| { Some( cx.view_ui_name(panel.as_any().window_id(), panel.id())? .to_string(), @@ -2853,7 +2863,7 @@ impl Workspace { let bottom_dock = this.bottom_dock.read(cx); let bottom_visible = bottom_dock.is_open(); - let bottom_active_panel = bottom_dock.active_panel().and_then(|panel| { + let bottom_active_panel = bottom_dock.visible_panel().and_then(|panel| { Some( cx.view_ui_name(panel.as_any().window_id(), panel.id())? .to_string(), @@ -3035,7 +3045,7 @@ impl Workspace { DockPosition::Right => &self.right_dock, DockPosition::Bottom => &self.bottom_dock, }; - let active_panel = dock.read(cx).active_panel()?; + let active_panel = dock.read(cx).visible_panel()?; let element = if Some(active_panel.id()) == self.zoomed.as_ref().map(|zoomed| zoomed.id()) { dock.read(cx).render_placeholder(cx) } else { @@ -4171,6 +4181,82 @@ mod tests { }); } + #[gpui::test] + async fn test_toggle_panel_focus(cx: &mut gpui::TestAppContext) { + init_test(cx); + let fs = FakeFs::new(cx.background()); + + let project = Project::test(fs, [], cx).await; + let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx)); + + let panel = workspace.update(cx, |workspace, cx| { + let panel = cx.add_view(|_| TestPanel::new(DockPosition::Right)); + workspace.add_panel(panel.clone(), cx); + + workspace + .right_dock() + .update(cx, |right_dock, cx| right_dock.set_open(true, cx)); + + panel + }); + + // Transfer focus from center to panel + workspace.update(cx, |workspace, cx| { + workspace.toggle_panel_focus::(cx); + }); + + workspace.read_with(cx, |workspace, cx| { + assert!(workspace.right_dock().read(cx).is_open()); + assert!(!panel.is_zoomed(cx)); + assert!(panel.has_focus(cx)); + }); + + // Transfer focus from panel to center + workspace.update(cx, |workspace, cx| { + workspace.toggle_panel_focus::(cx); + }); + + workspace.read_with(cx, |workspace, cx| { + assert!(workspace.right_dock().read(cx).is_open()); + assert!(!panel.is_zoomed(cx)); + assert!(!panel.has_focus(cx)); + }); + + // Focus and zoom panel + panel.update(cx, |panel, cx| { + cx.focus_self(); + panel.set_zoomed(true, cx) + }); + + workspace.read_with(cx, |workspace, cx| { + assert!(workspace.right_dock().read(cx).is_open()); + assert!(panel.is_zoomed(cx)); + assert!(panel.has_focus(cx)); + }); + + // Transfer focus to the center closes the dock + workspace.update(cx, |workspace, cx| { + workspace.toggle_panel_focus::(cx); + }); + + workspace.read_with(cx, |workspace, cx| { + assert!(!workspace.right_dock().read(cx).is_open()); + assert!(panel.is_zoomed(cx)); + assert!(!panel.has_focus(cx)); + }); + + // Transfering focus back to the panel keeps it zoomed + workspace.update(cx, |workspace, cx| { + workspace.toggle_panel_focus::(cx); + }); + + workspace.read_with(cx, |workspace, cx| { + assert!(workspace.right_dock().read(cx).is_open()); + assert!(panel.is_zoomed(cx)); + assert!(panel.has_focus(cx)); + }); + } + #[gpui::test] async fn test_panels(cx: &mut gpui::TestAppContext) { init_test(cx); @@ -4194,7 +4280,7 @@ mod tests { let left_dock = workspace.left_dock(); assert_eq!( - left_dock.read(cx).active_panel().unwrap().id(), + left_dock.read(cx).visible_panel().unwrap().id(), panel_1.id() ); assert_eq!( @@ -4204,7 +4290,12 @@ mod tests { left_dock.update(cx, |left_dock, cx| left_dock.resize_active_panel(1337., cx)); assert_eq!( - workspace.right_dock().read(cx).active_panel().unwrap().id(), + workspace + .right_dock() + .read(cx) + .visible_panel() + .unwrap() + .id(), panel_2.id() ); @@ -4220,10 +4311,10 @@ mod tests { // Since panel_1 was visible on the left, it should now be visible now that it's been moved to the right. // Since it was the only panel on the left, the left dock should now be closed. assert!(!workspace.left_dock().read(cx).is_open()); - assert!(workspace.left_dock().read(cx).active_panel().is_none()); + assert!(workspace.left_dock().read(cx).visible_panel().is_none()); let right_dock = workspace.right_dock(); assert_eq!( - right_dock.read(cx).active_panel().unwrap().id(), + right_dock.read(cx).visible_panel().unwrap().id(), panel_1.id() ); assert_eq!(right_dock.read(cx).active_panel_size(cx).unwrap(), 1337.); @@ -4238,7 +4329,12 @@ mod tests { // And the right dock is unaffected in it's displaying of panel_1 assert!(workspace.right_dock().read(cx).is_open()); assert_eq!( - workspace.right_dock().read(cx).active_panel().unwrap().id(), + workspace + .right_dock() + .read(cx) + .visible_panel() + .unwrap() + .id(), panel_1.id() ); }); @@ -4253,7 +4349,7 @@ mod tests { let left_dock = workspace.left_dock(); assert!(left_dock.read(cx).is_open()); assert_eq!( - left_dock.read(cx).active_panel().unwrap().id(), + left_dock.read(cx).visible_panel().unwrap().id(), panel_1.id() ); assert_eq!(left_dock.read(cx).active_panel_size(cx).unwrap(), 1337.); @@ -4287,7 +4383,7 @@ mod tests { let left_dock = workspace.left_dock(); assert!(left_dock.read(cx).is_open()); assert_eq!( - left_dock.read(cx).active_panel().unwrap().id(), + left_dock.read(cx).visible_panel().unwrap().id(), panel_1.id() ); assert!(panel_1.is_focused(cx)); @@ -4301,7 +4397,7 @@ mod tests { let left_dock = workspace.left_dock(); assert!(left_dock.read(cx).is_open()); assert_eq!( - left_dock.read(cx).active_panel().unwrap().id(), + left_dock.read(cx).visible_panel().unwrap().id(), panel_1.id() ); }); From 1a23fe91b47e78705afe26cf0e47826dc6ffec6f Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 30 May 2023 12:00:15 -0700 Subject: [PATCH 2/9] WIP: Remove focus side effects from toggle dock commands co-authored-by: max --- assets/keymaps/default.json | 27 ++-------------- crates/welcome/src/welcome.rs | 2 +- crates/workspace/src/workspace.rs | 51 ++++++------------------------- crates/zed/src/menus.rs | 6 ++-- crates/zed/src/zed.rs | 2 +- 5 files changed, 18 insertions(+), 70 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 35182dfaa6..7e1a8429bf 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -373,30 +373,9 @@ "workspace::ActivatePane", 8 ], - "cmd-b": [ - "workspace::ToggleLeftDock", - { "focus": true } - ], - "cmd-shift-b": [ - "workspace::ToggleLeftDock", - { "focus": false } - ], - "cmd-r": [ - "workspace::ToggleRightDock", - { "focus": true } - ], - "cmd-shift-r": [ - "workspace::ToggleRightDock", - { "focus": false } - ], - "cmd-j": [ - "workspace::ToggleBottomDock", - { "focus": true } - ], - "cmd-shift-j": [ - "workspace::ToggleBottomDock", - { "focus": false } - ], + "cmd-b": "workspace::ToggleLeftDock", + "cmd-r": "workspace::ToggleRightDock", + "cmd-j": "workspace::ToggleBottomDock", "cmd-shift-f": "workspace::NewSearch", "cmd-k cmd-t": "theme_selector::Toggle", "cmd-k cmd-s": "zed::OpenKeymap", diff --git a/crates/welcome/src/welcome.rs b/crates/welcome/src/welcome.rs index cef6f53a6e..b7460c4c46 100644 --- a/crates/welcome/src/welcome.rs +++ b/crates/welcome/src/welcome.rs @@ -32,7 +32,7 @@ pub fn init(cx: &mut AppContext) { pub fn show_welcome_experience(app_state: &Arc, cx: &mut AppContext) { open_new(&app_state, cx, |workspace, cx| { - workspace.toggle_dock(DockPosition::Left, false, cx); + workspace.toggle_dock(DockPosition::Left, cx); let welcome_page = cx.add_view(|cx| WelcomePage::new(workspace, cx)); workspace.add_item_to_center(Box::new(welcome_page.clone()), cx); cx.focus(&welcome_page); diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 6309b1d01f..1a14f39fb9 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -103,24 +103,6 @@ pub trait Modal: View { #[derive(Clone, PartialEq)] pub struct RemoveWorktreeFromProject(pub WorktreeId); -#[derive(Copy, Clone, Default, Deserialize, PartialEq)] -pub struct ToggleLeftDock { - #[serde(default = "default_true")] - pub focus: bool, -} - -#[derive(Copy, Clone, Default, Deserialize, PartialEq)] -pub struct ToggleBottomDock { - #[serde(default = "default_true")] - pub focus: bool, -} - -#[derive(Copy, Clone, Default, Deserialize, PartialEq)] -pub struct ToggleRightDock { - #[serde(default = "default_true")] - pub focus: bool, -} - actions!( workspace, [ @@ -143,16 +125,14 @@ actions!( Restart, Welcome, ToggleZoom, + ToggleLeftDock, + ToggleRightDock, + ToggleBottomDock, ] ); actions!(zed, [OpenSettings]); -impl_actions!( - workspace, - [ToggleLeftDock, ToggleBottomDock, ToggleRightDock] -); - #[derive(Clone, PartialEq)] pub struct OpenPaths { pub paths: Vec, @@ -268,14 +248,14 @@ pub fn init(app_state: Arc, cx: &mut AppContext) { cx.add_action(|workspace: &mut Workspace, _: &ActivateNextPane, cx| { workspace.activate_next_pane(cx) }); - cx.add_action(|workspace: &mut Workspace, action: &ToggleLeftDock, cx| { - workspace.toggle_dock(DockPosition::Left, action.focus, cx); + cx.add_action(|workspace: &mut Workspace, _: &ToggleLeftDock, cx| { + workspace.toggle_dock(DockPosition::Left, cx); }); - cx.add_action(|workspace: &mut Workspace, action: &ToggleRightDock, cx| { - workspace.toggle_dock(DockPosition::Right, action.focus, cx); + cx.add_action(|workspace: &mut Workspace, _: &ToggleRightDock, cx| { + workspace.toggle_dock(DockPosition::Right, cx); }); - cx.add_action(|workspace: &mut Workspace, action: &ToggleBottomDock, cx| { - workspace.toggle_dock(DockPosition::Bottom, action.focus, cx); + cx.add_action(|workspace: &mut Workspace, _: &ToggleBottomDock, cx| { + workspace.toggle_dock(DockPosition::Bottom, cx); }); cx.add_action(Workspace::activate_pane_at_index); cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| { @@ -1596,7 +1576,6 @@ impl Workspace { pub fn toggle_dock( &mut self, dock_side: DockPosition, - focus: bool, cx: &mut ViewContext, ) { let dock = match dock_side { @@ -1608,12 +1587,6 @@ impl Workspace { let open = !dock.is_open(); dock.set_open(open, cx); }); - - if dock.read(cx).is_open() && focus { - cx.focus(dock); - } else { - cx.focus_self(); - } cx.notify(); self.serialize_workspace(cx); } @@ -3599,10 +3572,6 @@ fn parse_pixel_position_env_var(value: &str) -> Option { Some(vec2f(width as f32, height as f32)) } -fn default_true() -> bool { - true -} - #[cfg(test)] mod tests { use super::*; @@ -4187,7 +4156,7 @@ mod tests { let fs = FakeFs::new(cx.background()); let project = Project::test(fs, [], cx).await; - let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx)); + let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx)); let panel = workspace.update(cx, |workspace, cx| { let panel = cx.add_view(|_| TestPanel::new(DockPosition::Right)); diff --git a/crates/zed/src/menus.rs b/crates/zed/src/menus.rs index adc1f81589..ecfd567e78 100644 --- a/crates/zed/src/menus.rs +++ b/crates/zed/src/menus.rs @@ -91,15 +91,15 @@ pub fn menus() -> Vec> { MenuItem::separator(), MenuItem::action( "Toggle Left Dock", - workspace::ToggleLeftDock { focus: false }, + workspace::ToggleLeftDock, ), MenuItem::action( "Toggle Right Dock", - workspace::ToggleRightDock { focus: false }, + workspace::ToggleRightDock, ), MenuItem::action( "Toggle Bottom Dock", - workspace::ToggleBottomDock { focus: false }, + workspace::ToggleBottomDock, ), MenuItem::submenu(Menu { name: "Editor Layout", diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index c22967686a..6dbddae2ad 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -354,7 +354,7 @@ pub fn initialize_workspace( .map_or(false, |entry| entry.is_dir()) }) { - workspace.toggle_dock(project_panel_position, false, cx); + workspace.toggle_dock(project_panel_position, cx); } workspace.add_panel(terminal_panel, cx) From 9c9af5ed94291ad1e019c671552abdc6b2c193fb Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 30 May 2023 12:32:00 -0700 Subject: [PATCH 3/9] Remove focus side effects from toggle dock commands co-authored-by: max --- crates/workspace/src/dock.rs | 7 +-- crates/workspace/src/workspace.rs | 77 +++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index fbfcbad817..13bebc5673 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -201,7 +201,7 @@ impl Dock { self.active_panel_index } - pub fn set_open(&mut self, open: bool, cx: &mut ViewContext) { + pub(crate) fn set_open(&mut self, open: bool, cx: &mut ViewContext) { if open != self.is_open { self.is_open = open; if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) { @@ -212,11 +212,6 @@ impl Dock { } } - pub fn toggle_open(&mut self, cx: &mut ViewContext) { - self.set_open(!self.is_open, cx); - cx.notify(); - } - pub fn set_panel_zoomed( &mut self, panel: &AnyViewHandle, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 1a14f39fb9..657285388a 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1583,10 +1583,27 @@ impl Workspace { DockPosition::Bottom => &self.bottom_dock, DockPosition::Right => &self.right_dock, }; - dock.update(cx, |dock, cx| { - let open = !dock.is_open(); - dock.set_open(open, cx); + let focus_center = dock.update(cx, |dock, cx| { + let was_open = dock.is_open(); + dock.set_open(!was_open, cx); + + if let Some(active_panel) = dock.active_panel() { + if was_open { + if active_panel.has_focus(cx) { + return true; + } + } else if active_panel.is_zoomed(cx) { + cx.focus(active_panel.as_any()); + } + } + + false }); + + if focus_center { + cx.focus_self(); + } + cx.notify(); self.serialize_workspace(cx); } @@ -1639,15 +1656,13 @@ impl Workspace { if panel.is_zoomed(cx) { dock.set_open(false, cx); } - true + return true } else { dock.set_open(true, cx); cx.focus(panel.as_any()); - false } - } else { - false } + false }); if focus_center { @@ -4151,7 +4166,7 @@ mod tests { } #[gpui::test] - async fn test_toggle_panel_focus(cx: &mut gpui::TestAppContext) { + async fn test_toggle_docks_and_panels(cx: &mut gpui::TestAppContext) { init_test(cx); let fs = FakeFs::new(cx.background()); @@ -4191,6 +4206,28 @@ mod tests { assert!(!panel.has_focus(cx)); }); + // Close the dock + workspace.update(cx, |workspace, cx| { + workspace.toggle_dock(DockPosition::Right, cx); + }); + + workspace.read_with(cx, |workspace, cx| { + assert!(!workspace.right_dock().read(cx).is_open()); + assert!(!panel.is_zoomed(cx)); + assert!(!panel.has_focus(cx)); + }); + + // Open the dock + workspace.update(cx, |workspace, cx| { + workspace.toggle_dock(DockPosition::Right, cx); + }); + + workspace.read_with(cx, |workspace, cx| { + assert!(workspace.right_dock().read(cx).is_open()); + assert!(!panel.is_zoomed(cx)); + assert!(!panel.has_focus(cx)); + }); + // Focus and zoom panel panel.update(cx, |panel, cx| { cx.focus_self(); @@ -4224,6 +4261,30 @@ mod tests { assert!(panel.is_zoomed(cx)); assert!(panel.has_focus(cx)); }); + + // Close the dock while it is zoomed + workspace.update(cx, |workspace, cx| { + workspace.toggle_dock(DockPosition::Right, cx) + }); + + workspace.read_with(cx, |workspace, cx| { + assert!(!workspace.right_dock().read(cx).is_open()); + assert!(panel.is_zoomed(cx)); + assert!(workspace.zoomed.is_none()); + assert!(!panel.has_focus(cx)); + }); + + // Opening the dock, when it's zoomed, retains focus + workspace.update(cx, |workspace, cx| { + workspace.toggle_dock(DockPosition::Right, cx) + }); + + workspace.read_with(cx, |workspace, cx| { + assert!(workspace.right_dock().read(cx).is_open()); + assert!(panel.is_zoomed(cx)); + assert!(workspace.zoomed.is_some()); + assert!(panel.has_focus(cx)); + }); } #[gpui::test] From 506580438803a2ef050c40351a0841596f6b4952 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 30 May 2023 14:55:49 -0700 Subject: [PATCH 4/9] WIP: iron out bugs in interaction between toggle and toggle focus key bindings co-authored-by: max --- crates/workspace/src/workspace.rs | 143 +++++++++++++++++++++++++----- 1 file changed, 122 insertions(+), 21 deletions(-) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 657285388a..53240a9a73 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -478,6 +478,7 @@ pub struct Workspace { remote_entity_subscription: Option, modal: Option, zoomed: Option, + zoomed_position: Option, center: PaneGroup, left_dock: ViewHandle, bottom_dock: ViewHandle, @@ -683,6 +684,7 @@ impl Workspace { weak_self: weak_handle.clone(), modal: None, zoomed: None, + zoomed_position: None, center: PaneGroup::new(center_pane.clone()), panes: vec![center_pane.clone()], panes_by_item: Default::default(), @@ -885,6 +887,11 @@ impl Workspace { .map_or(false, |active_panel| active_panel.id() == panel.id()); dock.remove_panel(&panel, cx); }); + + if panel.is_zoomed(cx) { + this.zoomed_position = Some(new_position); + } + dock = match panel.read(cx).position(cx) { DockPosition::Left => &this.left_dock, DockPosition::Bottom => &this.bottom_dock, @@ -903,14 +910,17 @@ impl Workspace { dock.update(cx, |dock, cx| dock.set_panel_zoomed(&panel, true, cx)); if panel.has_focus(cx) { this.zoomed = Some(panel.downgrade().into_any()); + this.zoomed_position = Some(panel.read(cx).position(cx)); } } else if T::should_zoom_out_on_event(event) { this.zoom_out(cx); } else if T::is_focus_event(event) { if panel.is_zoomed(cx) { this.zoomed = Some(panel.downgrade().into_any()); + this.zoomed_position = Some(panel.read(cx).position(cx)); } else { this.zoomed = None; + this.zoomed_position = None; } cx.notify(); } @@ -1573,33 +1583,36 @@ impl Workspace { } } - pub fn toggle_dock( - &mut self, - dock_side: DockPosition, - cx: &mut ViewContext, - ) { + pub fn toggle_dock(&mut self, dock_side: DockPosition, cx: &mut ViewContext) { let dock = match dock_side { DockPosition::Left => &self.left_dock, DockPosition::Bottom => &self.bottom_dock, DockPosition::Right => &self.right_dock, }; - let focus_center = dock.update(cx, |dock, cx| { - let was_open = dock.is_open(); - dock.set_open(!was_open, cx); + let mut focus_center = false; + let mut zoom_out = false; + dock.update(cx, |dock, cx| { + let other_is_zoomed = self.zoomed.is_some() && self.zoomed_position != Some(dock_side); + let was_visible = dock.is_open() && !other_is_zoomed; + dock.set_open(!was_visible, cx); if let Some(active_panel) = dock.active_panel() { - if was_open { + if was_visible { if active_panel.has_focus(cx) { - return true; + focus_center = true; } - } else if active_panel.is_zoomed(cx) { - cx.focus(active_panel.as_any()); + } else { + if active_panel.is_zoomed(cx) { + cx.focus(active_panel.as_any()); + } + zoom_out = true; } } - - false }); + if zoom_out { + self.zoom_out_everything_except(dock_side, cx); + } if focus_center { cx.focus_self(); } @@ -1646,9 +1659,24 @@ impl Workspace { } pub fn toggle_panel_focus(&mut self, cx: &mut ViewContext) { - for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] { + for (dock, position) in [ + self.left_dock.clone(), + self.bottom_dock.clone(), + self.right_dock.clone(), + ] + .into_iter() + .zip( + [ + DockPosition::Left, + DockPosition::Bottom, + DockPosition::Right, + ] + .into_iter(), + ) { if let Some(panel_index) = dock.read(cx).panel_index_for_type::() { - let focus_center = dock.update(cx, |dock, cx| { + let mut focus_center = false; + let mut zoom_out = false; + dock.update(cx, |dock, cx| { dock.activate_panel(panel_index, cx); if let Some(panel) = dock.active_panel().cloned() { @@ -1656,15 +1684,18 @@ impl Workspace { if panel.is_zoomed(cx) { dock.set_open(false, cx); } - return true + focus_center = true; } else { dock.set_open(true, cx); cx.focus(panel.as_any()); + zoom_out = true; } } - false }); + if zoom_out { + self.zoom_out_everything_except(position, cx); + } if focus_center { cx.focus_self(); } @@ -1685,6 +1716,36 @@ impl Workspace { self.bottom_dock.update(cx, |dock, cx| dock.zoom_out(cx)); self.right_dock.update(cx, |dock, cx| dock.zoom_out(cx)); self.zoomed = None; + self.zoomed_position = None; + + cx.notify(); + } + + fn zoom_out_everything_except( + &mut self, + except_position: DockPosition, + cx: &mut ViewContext, + ) { + for pane in &self.panes { + pane.update(cx, |pane, cx| pane.set_zoomed(false, cx)); + } + + if except_position != DockPosition::Left { + self.left_dock.update(cx, |dock, cx| dock.zoom_out(cx)); + } + + if except_position != DockPosition::Bottom { + self.bottom_dock.update(cx, |dock, cx| dock.zoom_out(cx)); + } + + if except_position != DockPosition::Right { + self.right_dock.update(cx, |dock, cx| dock.zoom_out(cx)); + } + + if self.zoomed_position != Some(except_position) { + self.zoomed = None; + self.zoomed_position = None; + } cx.notify(); } @@ -1901,6 +1962,7 @@ impl Workspace { } else { self.zoomed = None; } + self.zoomed_position = None; self.update_followers( proto::update_followers::Variant::UpdateActiveView(proto::UpdateActiveView { @@ -1960,6 +2022,7 @@ impl Workspace { pane.update(cx, |pane, cx| pane.set_zoomed(true, cx)); if pane.read(cx).has_focus() { self.zoomed = Some(pane.downgrade().into_any()); + self.zoomed_position = None; } cx.notify(); } @@ -3234,13 +3297,38 @@ impl View for Workspace { .with_children(self.zoomed.as_ref().and_then(|zoomed| { enum ZoomBackground {} let zoomed = zoomed.upgrade(cx)?; + + let mut background_style = + theme.workspace.zoomed_background; + match self.zoomed_position { + Some(DockPosition::Left) => { + background_style.padding.left = 0.; + background_style.padding.top = 0.; + background_style.padding.bottom = 0.; + background_style.padding.right *= 1.; + } + Some(DockPosition::Right) => { + background_style.padding.right = 0.; + background_style.padding.top = 0.; + background_style.padding.bottom = 0.; + background_style.padding.left *= 1.; + } + Some(DockPosition::Bottom) => { + background_style.padding.left = 0.; + background_style.padding.right = 0.; + background_style.padding.bottom = 0.; + background_style.padding.top *= 1.; + } + None => {} + } + Some( ChildView::new(&zoomed, cx) .contained() .with_style(theme.workspace.zoomed_foreground) .aligned() .contained() - .with_style(theme.workspace.zoomed_background) + .with_style(background_style) .mouse::(0) .capture_all() .on_down( @@ -4436,6 +4524,14 @@ mod tests { panel_1.update(cx, |_, cx| cx.emit(TestPanelEvent::ZoomIn)); workspace.read_with(cx, |workspace, _| { assert_eq!(workspace.zoomed, Some(panel_1.downgrade().into_any())); + assert_eq!(workspace.zoomed_position, Some(DockPosition::Left)); + }); + + // Move panel to another dock while it is zoomed + panel_1.update(cx, |panel, cx| panel.set_position(DockPosition::Right, cx)); + workspace.read_with(cx, |workspace, _| { + assert_eq!(workspace.zoomed, Some(panel_1.downgrade().into_any())); + assert_eq!(workspace.zoomed_position, Some(DockPosition::Right)); }); // If focus is transferred to another view that's not a panel or another pane, we still show @@ -4444,12 +4540,14 @@ mod tests { focus_receiver.update(cx, |_, cx| cx.focus_self()); workspace.read_with(cx, |workspace, _| { assert_eq!(workspace.zoomed, Some(panel_1.downgrade().into_any())); + assert_eq!(workspace.zoomed_position, Some(DockPosition::Right)); }); // If focus is transferred elsewhere in the workspace, the panel is no longer zoomed. workspace.update(cx, |_, cx| cx.focus_self()); workspace.read_with(cx, |workspace, _| { assert_eq!(workspace.zoomed, None); + assert_eq!(workspace.zoomed_position, None); }); // If focus is transferred again to another view that's not a panel or a pane, we won't @@ -4457,18 +4555,21 @@ mod tests { focus_receiver.update(cx, |_, cx| cx.focus_self()); workspace.read_with(cx, |workspace, _| { assert_eq!(workspace.zoomed, None); + assert_eq!(workspace.zoomed_position, None); }); // When focus is transferred back to the panel, it is zoomed again. panel_1.update(cx, |_, cx| cx.focus_self()); workspace.read_with(cx, |workspace, _| { assert_eq!(workspace.zoomed, Some(panel_1.downgrade().into_any())); + assert_eq!(workspace.zoomed_position, Some(DockPosition::Right)); }); // Emitting a ZoomOut event unzooms the panel. panel_1.update(cx, |_, cx| cx.emit(TestPanelEvent::ZoomOut)); workspace.read_with(cx, |workspace, _| { assert_eq!(workspace.zoomed, None); + assert_eq!(workspace.zoomed_position, None); }); // Emit closed event on panel 1, which is active @@ -4476,8 +4577,8 @@ mod tests { // Now the left dock is closed, because panel_1 was the active panel workspace.read_with(cx, |workspace, cx| { - let left_dock = workspace.left_dock(); - assert!(!left_dock.read(cx).is_open()); + let right_dock = workspace.right_dock(); + assert!(!right_dock.read(cx).is_open()); }); } From 5e4a9abd0907eff8412c8a65df0d6f89bd16eb59 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 30 May 2023 15:17:42 -0700 Subject: [PATCH 5/9] Fix bug in panel button dispatch --- crates/workspace/src/dock.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 13bebc5673..2f198f62f4 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -503,13 +503,21 @@ impl View for PanelButtons { }) .with_cursor_style(CursorStyle::PointingHand) .on_click(MouseButton::Left, { + let tooltip_action = + tooltip_action.as_ref().map(|action| action.boxed_clone()); move |_, this, cx| { - if let Some(workspace) = this.workspace.upgrade(cx) { - cx.window_context().defer(move |cx| { - workspace.update(cx, |workspace, cx| { - workspace.toggle_panel(dock_position, panel_ix, cx) - }); - }); + if let Some(tooltip_action) = &tooltip_action { + let window_id = cx.window_id(); + let view_id = this.workspace.id(); + let tooltip_action = tooltip_action.boxed_clone(); + cx.spawn(|_, mut cx| async move { + cx.dispatch_action( + window_id, + view_id, + &*tooltip_action, + ) + .ok(); + }).detach(); } } }) From e80ab5f096bae73e6522d120370089d8cb0104be Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 30 May 2023 15:40:30 -0700 Subject: [PATCH 6/9] Fix focus bug with new docks co-authored-by: max --- crates/workspace/src/pane.rs | 15 ++++----------- crates/workspace/src/workspace.rs | 6 +----- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 2919bb7cd4..e722b3be6a 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -306,15 +306,6 @@ impl Pane { &self.workspace } - pub fn is_active(&self) -> bool { - self.is_active - } - - pub fn set_active(&mut self, is_active: bool, cx: &mut ViewContext) { - self.is_active = is_active; - cx.notify(); - } - pub fn has_focus(&self) -> bool { self.has_focus } @@ -1129,7 +1120,7 @@ impl Pane { None }; - let pane_active = self.is_active; + let pane_active = self.has_focus; enum Tabs {} let mut row = Flex::row().scrollable::(1, autoscroll, cx); @@ -1508,7 +1499,7 @@ impl View for Pane { let mut tab_row = Flex::row() .with_child(self.render_tabs(cx).flex(1., true).into_any_named("tabs")); - if self.is_active { + if self.has_focus { let render_tab_bar_buttons = self.render_tab_bar_buttons.clone(); tab_row.add_child( (render_tab_bar_buttons)(self, cx) @@ -1599,6 +1590,7 @@ impl View for Pane { if !self.has_focus { self.has_focus = true; cx.emit(Event::Focus); + cx.notify(); } self.toolbar.update(cx, |toolbar, cx| { @@ -1633,6 +1625,7 @@ impl View for Pane { self.toolbar.update(cx, |toolbar, cx| { toolbar.pane_focus_update(false, cx); }); + cx.notify(); } fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 53240a9a73..e51a0bf812 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1945,11 +1945,7 @@ impl Workspace { fn handle_pane_focused(&mut self, pane: ViewHandle, cx: &mut ViewContext) { if self.active_pane != pane { - self.active_pane - .update(cx, |pane, cx| pane.set_active(false, cx)); self.active_pane = pane.clone(); - self.active_pane - .update(cx, |pane, cx| pane.set_active(true, cx)); self.status_bar.update(cx, |status_bar, cx| { status_bar.set_active_pane(&self.active_pane, cx); }); @@ -2868,7 +2864,7 @@ impl Workspace { }) }) .collect::>(), - pane.is_active(), + pane.has_focus(), ) }; From 9c707eff27c61136ff995d1462d3cbdadca9822b Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 30 May 2023 16:10:07 -0700 Subject: [PATCH 7/9] Rework new terminal actions --- crates/terminal_view/src/terminal_panel.rs | 19 +++++-- crates/terminal_view/src/terminal_view.rs | 8 +-- crates/workspace/src/pane.rs | 6 +- crates/workspace/src/workspace.rs | 64 +++++++--------------- 4 files changed, 41 insertions(+), 56 deletions(-) diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index d34a261bfe..c2f7eb36e4 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -22,7 +22,7 @@ const TERMINAL_PANEL_KEY: &'static str = "TerminalPanel"; actions!(terminal_panel, [ToggleFocus]); pub fn init(cx: &mut AppContext) { - cx.add_action(TerminalPanel::add_terminal); + cx.add_action(TerminalPanel::new_terminal); } pub enum Event { @@ -80,7 +80,7 @@ impl TerminalPanel { cx.window_context().defer(move |cx| { if let Some(this) = this.upgrade(cx) { this.update(cx, |this, cx| { - this.add_terminal(&Default::default(), cx); + this.add_terminal(cx); }); } }) @@ -220,7 +220,18 @@ impl TerminalPanel { } } - fn add_terminal(&mut self, _: &workspace::NewTerminal, cx: &mut ViewContext) { + + fn new_terminal(workspace: &mut Workspace, _: &workspace::NewTerminal, cx: &mut ViewContext) { + let Some(this) = workspace.focus_panel::(cx) else { + return; + }; + + this.update(cx, |this, cx| { + this.add_terminal(cx) + }) + } + + fn add_terminal(&mut self, cx: &mut ViewContext) { let workspace = self.workspace.clone(); cx.spawn(|this, mut cx| async move { let pane = this.read_with(&cx, |this, _| this.pane.clone())?; @@ -363,7 +374,7 @@ impl Panel for TerminalPanel { fn set_active(&mut self, active: bool, cx: &mut ViewContext) { if active && self.pane.read(cx).items_len() == 0 { - self.add_terminal(&Default::default(), cx) + self.add_terminal(cx) } } diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 767e3bf4db..633b83afb8 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -38,7 +38,7 @@ use workspace::{ notifications::NotifyResultExt, pane, register_deserializable_item, searchable::{SearchEvent, SearchOptions, SearchableItem, SearchableItemHandle}, - Pane, ToolbarItemLocation, Workspace, WorkspaceId, + Pane, ToolbarItemLocation, Workspace, WorkspaceId, NewCenterTerminal, }; pub use terminal::TerminalSettings; @@ -66,10 +66,10 @@ pub fn init(cx: &mut AppContext) { terminal_panel::init(cx); terminal::init(cx); - cx.add_action(TerminalView::deploy); - register_deserializable_item::(cx); + cx.add_action(TerminalView::deploy); + //Useful terminal views cx.add_action(TerminalView::send_text); cx.add_action(TerminalView::send_keystroke); @@ -101,7 +101,7 @@ impl TerminalView { ///Create a new Terminal in the current working directory or the user's home directory pub fn deploy( workspace: &mut Workspace, - _: &workspace::NewTerminal, + _: &NewCenterTerminal, cx: &mut ViewContext, ) { let strategy = settings::get::(cx); diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index e722b3be6a..23d3d6f378 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -3,7 +3,7 @@ mod dragged_item_receiver; use super::{ItemHandle, SplitDirection}; use crate::{ item::WeakItemHandle, toolbar::Toolbar, AutosaveSetting, Item, NewFile, NewSearch, NewTerminal, - ToggleZoom, Workspace, WorkspaceSettings, + ToggleZoom, Workspace, WorkspaceSettings, NewCenterTerminal, }; use anyhow::Result; use collections::{HashMap, HashSet, VecDeque}; @@ -131,7 +131,6 @@ pub enum Event { pub struct Pane { items: Vec>, activation_history: Vec, - is_active: bool, zoomed: bool, active_item_index: usize, last_focused_view_by_item: HashMap, @@ -238,7 +237,6 @@ impl Pane { Self { items: Vec::new(), activation_history: Vec::new(), - is_active: true, zoomed: false, active_item_index: 0, last_focused_view_by_item: Default::default(), @@ -996,7 +994,7 @@ impl Pane { AnchorCorner::TopRight, vec![ ContextMenuItem::action("New File", NewFile), - ContextMenuItem::action("New Terminal", NewTerminal), + ContextMenuItem::action("New Terminal", NewCenterTerminal), ContextMenuItem::action("New Search", NewSearch), ], cx, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index e51a0bf812..9285e911ef 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -55,7 +55,7 @@ use std::{ path::{Path, PathBuf}, str, sync::{atomic::AtomicUsize, Arc}, - time::Duration, + time::Duration, rc::Rc, }; use crate::{ @@ -119,6 +119,7 @@ actions!( ActivateNextPane, FollowNextCollaborator, NewTerminal, + NewCenterTerminal, ToggleTerminalFocus, NewSearch, Feedback, @@ -1621,44 +1622,15 @@ impl Workspace { self.serialize_workspace(cx); } - pub fn toggle_panel( - &mut self, - position: DockPosition, - panel_index: usize, - cx: &mut ViewContext, - ) { - let dock = match position { - DockPosition::Left => &mut self.left_dock, - DockPosition::Bottom => &mut self.bottom_dock, - DockPosition::Right => &mut self.right_dock, - }; - let active_item = dock.update(cx, move |dock, cx| { - if dock.is_open() && dock.active_panel_index() == panel_index { - dock.set_open(false, cx); - None - } else { - dock.set_open(true, cx); - dock.activate_panel(panel_index, cx); - dock.visible_panel().cloned() - } - }); - - if let Some(active_item) = active_item { - if active_item.has_focus(cx) { - cx.focus_self(); - } else { - cx.focus(active_item.as_any()); - } - } else { - cx.focus_self(); - } - - self.serialize_workspace(cx); - - cx.notify(); + pub fn focus_panel(&mut self, cx: &mut ViewContext) -> Option> { + self.show_or_hide_panel::(cx, |_, _| true)?.as_any().clone().downcast() } pub fn toggle_panel_focus(&mut self, cx: &mut ViewContext) { + self.show_or_hide_panel::(cx, |panel, cx| !panel.has_focus(cx)); + } + + fn show_or_hide_panel(&mut self, cx: &mut ViewContext, show: impl Fn(&dyn PanelHandle, &mut ViewContext) -> bool) -> Option> { for (dock, position) in [ self.left_dock.clone(), self.bottom_dock.clone(), @@ -1676,21 +1648,24 @@ impl Workspace { if let Some(panel_index) = dock.read(cx).panel_index_for_type::() { let mut focus_center = false; let mut zoom_out = false; - dock.update(cx, |dock, cx| { + let panel = dock.update(cx, |dock, cx| { dock.activate_panel(panel_index, cx); - if let Some(panel) = dock.active_panel().cloned() { - if panel.has_focus(cx) { + let panel = dock.active_panel().cloned(); + if let Some(panel) = panel.as_ref() { + let should_show = show(&**panel, cx); + if should_show { + dock.set_open(true, cx); + cx.focus(panel.as_any()); + zoom_out = true; + } else { if panel.is_zoomed(cx) { dock.set_open(false, cx); } focus_center = true; - } else { - dock.set_open(true, cx); - cx.focus(panel.as_any()); - zoom_out = true; } } + panel }); if zoom_out { @@ -1702,9 +1677,10 @@ impl Workspace { self.serialize_workspace(cx); cx.notify(); - break; + return panel; } } + None } fn zoom_out(&mut self, cx: &mut ViewContext) { From 685e8d70072f7f3cfb0dd8beb7bf513c6aa205e7 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 30 May 2023 16:23:16 -0700 Subject: [PATCH 8/9] Seperate pane and panel styling co-authored-by: max --- crates/theme/src/theme.rs | 3 ++- crates/workspace/src/pane.rs | 2 +- crates/workspace/src/workspace.rs | 39 +++++++++++++++++-------------- styles/src/styleTree/workspace.ts | 10 +++++--- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index b1c9e9c215..21c01150a8 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -89,7 +89,8 @@ pub struct Workspace { pub breadcrumbs: Interactive, pub disconnected_overlay: ContainedText, pub modal: ContainerStyle, - pub zoomed_foreground: ContainerStyle, + pub zoomed_panel_foreground: ContainerStyle, + pub zoomed_pane_foreground: ContainerStyle, pub zoomed_background: ContainerStyle, pub notification: ContainerStyle, pub notifications: Notifications, diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 23d3d6f378..8dca08ec81 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -2,7 +2,7 @@ mod dragged_item_receiver; use super::{ItemHandle, SplitDirection}; use crate::{ - item::WeakItemHandle, toolbar::Toolbar, AutosaveSetting, Item, NewFile, NewSearch, NewTerminal, + item::WeakItemHandle, toolbar::Toolbar, AutosaveSetting, Item, NewFile, NewSearch, ToggleZoom, Workspace, WorkspaceSettings, NewCenterTerminal, }; use anyhow::Result; diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 9285e911ef..0aefe455ac 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -3270,37 +3270,42 @@ impl View for Workspace { enum ZoomBackground {} let zoomed = zoomed.upgrade(cx)?; - let mut background_style = - theme.workspace.zoomed_background; + let mut foreground_style; match self.zoomed_position { Some(DockPosition::Left) => { - background_style.padding.left = 0.; - background_style.padding.top = 0.; - background_style.padding.bottom = 0.; - background_style.padding.right *= 1.; + foreground_style = + theme.workspace.zoomed_panel_foreground; + foreground_style.margin.left = 0.; + foreground_style.margin.top = 0.; + foreground_style.margin.bottom = 0.; } Some(DockPosition::Right) => { - background_style.padding.right = 0.; - background_style.padding.top = 0.; - background_style.padding.bottom = 0.; - background_style.padding.left *= 1.; + foreground_style = + theme.workspace.zoomed_panel_foreground; + foreground_style.margin.right = 0.; + foreground_style.margin.top = 0.; + foreground_style.margin.bottom = 0.; } Some(DockPosition::Bottom) => { - background_style.padding.left = 0.; - background_style.padding.right = 0.; - background_style.padding.bottom = 0.; - background_style.padding.top *= 1.; + foreground_style = + theme.workspace.zoomed_panel_foreground; + foreground_style.margin.left = 0.; + foreground_style.margin.right = 0.; + foreground_style.margin.bottom = 0.; + } + None => { + foreground_style = + theme.workspace.zoomed_pane_foreground; } - None => {} } Some( ChildView::new(&zoomed, cx) .contained() - .with_style(theme.workspace.zoomed_foreground) + .with_style(foreground_style) .aligned() .contained() - .with_style(background_style) + .with_style(theme.workspace.zoomed_background) .mouse::(0) .capture_all() .on_down( diff --git a/styles/src/styleTree/workspace.ts b/styles/src/styleTree/workspace.ts index 737d225784..cf5234aa00 100644 --- a/styles/src/styleTree/workspace.ts +++ b/styles/src/styleTree/workspace.ts @@ -119,14 +119,18 @@ export default function workspace(colorScheme: ColorScheme) { cursor: "Arrow", }, zoomedBackground: { - padding: 10, cursor: "Arrow", - background: withOpacity(background(colorScheme.lowest), 0.5) + background: withOpacity(background(colorScheme.lowest), 0.85) }, - zoomedForeground: { + zoomedPaneForeground: { + margin: 10, shadow: colorScheme.modalShadow, border: border(colorScheme.highest, { overlay: true }), }, + zoomedPanelForeground: { + margin: 18, + border: border(colorScheme.highest, { overlay: true }), + }, dock: { left: { border: border(layer, { right: true }), From 0122cd61c555154c61f9f94c0c23f671c322bdf5 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 30 May 2023 16:33:42 -0700 Subject: [PATCH 9/9] fmt --- crates/terminal_view/src/terminal_panel.rs | 11 ++++++----- crates/terminal_view/src/terminal_view.rs | 2 +- crates/workspace/src/dock.rs | 3 ++- crates/workspace/src/pane.rs | 4 ++-- crates/workspace/src/workspace.rs | 14 +++++++++++--- crates/zed/src/menus.rs | 15 +++------------ 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index c2f7eb36e4..e45459e683 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -220,15 +220,16 @@ impl TerminalPanel { } } - - fn new_terminal(workspace: &mut Workspace, _: &workspace::NewTerminal, cx: &mut ViewContext) { + fn new_terminal( + workspace: &mut Workspace, + _: &workspace::NewTerminal, + cx: &mut ViewContext, + ) { let Some(this) = workspace.focus_panel::(cx) else { return; }; - this.update(cx, |this, cx| { - this.add_terminal(cx) - }) + this.update(cx, |this, cx| this.add_terminal(cx)) } fn add_terminal(&mut self, cx: &mut ViewContext) { diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 633b83afb8..7f43f99ebd 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -38,7 +38,7 @@ use workspace::{ notifications::NotifyResultExt, pane, register_deserializable_item, searchable::{SearchEvent, SearchOptions, SearchableItem, SearchableItemHandle}, - Pane, ToolbarItemLocation, Workspace, WorkspaceId, NewCenterTerminal, + NewCenterTerminal, Pane, ToolbarItemLocation, Workspace, WorkspaceId, }; pub use terminal::TerminalSettings; diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 2f198f62f4..886afe943d 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -517,7 +517,8 @@ impl View for PanelButtons { &*tooltip_action, ) .ok(); - }).detach(); + }) + .detach(); } } }) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 8dca08ec81..921ae5e010 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -2,8 +2,8 @@ mod dragged_item_receiver; use super::{ItemHandle, SplitDirection}; use crate::{ - item::WeakItemHandle, toolbar::Toolbar, AutosaveSetting, Item, NewFile, NewSearch, - ToggleZoom, Workspace, WorkspaceSettings, NewCenterTerminal, + item::WeakItemHandle, toolbar::Toolbar, AutosaveSetting, Item, NewCenterTerminal, NewFile, + NewSearch, ToggleZoom, Workspace, WorkspaceSettings, }; use anyhow::Result; use collections::{HashMap, HashSet, VecDeque}; diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 0aefe455ac..d051f6d80a 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -53,9 +53,10 @@ use std::{ cmp, env, future::Future, path::{Path, PathBuf}, + rc::Rc, str, sync::{atomic::AtomicUsize, Arc}, - time::Duration, rc::Rc, + time::Duration, }; use crate::{ @@ -1623,14 +1624,21 @@ impl Workspace { } pub fn focus_panel(&mut self, cx: &mut ViewContext) -> Option> { - self.show_or_hide_panel::(cx, |_, _| true)?.as_any().clone().downcast() + self.show_or_hide_panel::(cx, |_, _| true)? + .as_any() + .clone() + .downcast() } pub fn toggle_panel_focus(&mut self, cx: &mut ViewContext) { self.show_or_hide_panel::(cx, |panel, cx| !panel.has_focus(cx)); } - fn show_or_hide_panel(&mut self, cx: &mut ViewContext, show: impl Fn(&dyn PanelHandle, &mut ViewContext) -> bool) -> Option> { + fn show_or_hide_panel( + &mut self, + cx: &mut ViewContext, + show: impl Fn(&dyn PanelHandle, &mut ViewContext) -> bool, + ) -> Option> { for (dock, position) in [ self.left_dock.clone(), self.bottom_dock.clone(), diff --git a/crates/zed/src/menus.rs b/crates/zed/src/menus.rs index ecfd567e78..76e88325f5 100644 --- a/crates/zed/src/menus.rs +++ b/crates/zed/src/menus.rs @@ -89,18 +89,9 @@ pub fn menus() -> Vec> { MenuItem::action("Zoom Out", super::DecreaseBufferFontSize), MenuItem::action("Reset Zoom", super::ResetBufferFontSize), MenuItem::separator(), - MenuItem::action( - "Toggle Left Dock", - workspace::ToggleLeftDock, - ), - MenuItem::action( - "Toggle Right Dock", - workspace::ToggleRightDock, - ), - MenuItem::action( - "Toggle Bottom Dock", - workspace::ToggleBottomDock, - ), + MenuItem::action("Toggle Left Dock", workspace::ToggleLeftDock), + MenuItem::action("Toggle Right Dock", workspace::ToggleRightDock), + MenuItem::action("Toggle Bottom Dock", workspace::ToggleBottomDock), MenuItem::submenu(Menu { name: "Editor Layout", items: vec![