From 790d99538160327e8e1bc3b52e0fe4c91b63b78f Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 14 Jun 2023 23:04:41 -0700 Subject: [PATCH 1/5] Add focusing into the toggle dock commands --- crates/workspace/src/workspace.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index ef8cde78a64aa1260d6be8174b24eb418762ed4d..883b90d8090d4738d8d57c5400debf293b2685f3 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1598,9 +1598,7 @@ impl Workspace { focus_center = true; } } else { - if active_panel.is_zoomed(cx) { - cx.focus(active_panel.as_any()); - } + cx.focus(active_panel.as_any()); reveal_dock = true; } } From 6662066821b615d8d281856492452baab205ad7d Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 14 Jun 2023 23:43:45 -0700 Subject: [PATCH 2/5] Add zoom serialization to the workspace --- crates/workspace/src/persistence.rs | 27 +++++++++++++---- crates/workspace/src/persistence/model.rs | 6 +++- crates/workspace/src/workspace.rs | 35 +++++++++++++++++++++-- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/crates/workspace/src/persistence.rs b/crates/workspace/src/persistence.rs index d27818d2028eec866d17cc687bb393f37e9cb6e5..dd2aa5a818968c77e94f8ccb1ad0bcaf284f0ecb 100644 --- a/crates/workspace/src/persistence.rs +++ b/crates/workspace/src/persistence.rs @@ -162,6 +162,12 @@ define_connection! { ALTER TABLE workspaces ADD COLUMN right_dock_active_panel TEXT; ALTER TABLE workspaces ADD COLUMN bottom_dock_visible INTEGER; //bool ALTER TABLE workspaces ADD COLUMN bottom_dock_active_panel TEXT; + ), + // Add panel zoom persistence + sql!( + ALTER TABLE workspaces ADD COLUMN left_dock_zoom INTEGER; //bool + ALTER TABLE workspaces ADD COLUMN right_dock_zoom INTEGER; //bool + ALTER TABLE workspaces ADD COLUMN bottom_dock_zoom INTEGER; //bool )]; } @@ -196,10 +202,13 @@ impl WorkspaceDb { display, left_dock_visible, left_dock_active_panel, + left_dock_zoom, right_dock_visible, right_dock_active_panel, + right_dock_zoom, bottom_dock_visible, - bottom_dock_active_panel + bottom_dock_active_panel, + bottom_dock_zoom FROM workspaces WHERE workspace_location = ? }) @@ -244,22 +253,28 @@ impl WorkspaceDb { workspace_location, left_dock_visible, left_dock_active_panel, + left_dock_zoom, right_dock_visible, right_dock_active_panel, + right_dock_zoom, bottom_dock_visible, bottom_dock_active_panel, + bottom_dock_zoom, timestamp ) - VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, CURRENT_TIMESTAMP) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, CURRENT_TIMESTAMP) ON CONFLICT DO UPDATE SET workspace_location = ?2, left_dock_visible = ?3, left_dock_active_panel = ?4, - right_dock_visible = ?5, - right_dock_active_panel = ?6, - bottom_dock_visible = ?7, - bottom_dock_active_panel = ?8, + left_dock_zoom = ?5, + right_dock_visible = ?6, + right_dock_active_panel = ?7, + right_dock_zoom = ?8, + bottom_dock_visible = ?9, + bottom_dock_active_panel = ?10, + bottom_dock_zoom = ?11, timestamp = CURRENT_TIMESTAMP ))?((workspace.id, &workspace.location, workspace.docks)) .context("Updating workspace")?; diff --git a/crates/workspace/src/persistence/model.rs b/crates/workspace/src/persistence/model.rs index 9e3c4012cdcb77e082befb553488512f121569af..9a374907fb79bd678628e30e9b4d836d156f597c 100644 --- a/crates/workspace/src/persistence/model.rs +++ b/crates/workspace/src/persistence/model.rs @@ -100,16 +100,19 @@ impl Bind for DockStructure { pub struct DockData { pub(crate) visible: bool, pub(crate) active_panel: Option, + pub(crate) zoom: bool } impl Column for DockData { fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> { let (visible, next_index) = Option::::column(statement, start_index)?; let (active_panel, next_index) = Option::::column(statement, next_index)?; + let (zoom, next_index) = Option::::column(statement, next_index)?; Ok(( DockData { visible: visible.unwrap_or(false), active_panel, + zoom: zoom.unwrap_or(false) }, next_index, )) @@ -119,7 +122,8 @@ impl Column for DockData { impl Bind for DockData { fn bind(&self, statement: &Statement, start_index: i32) -> Result { let next_index = statement.bind(&self.visible, start_index)?; - statement.bind(&self.active_panel, next_index) + let next_index = statement.bind(&self.active_panel, next_index)?; + statement.bind(&self.zoom, next_index) } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 883b90d8090d4738d8d57c5400debf293b2685f3..da10f6ecee76cd2e5026c434702a63ea14f83758 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2836,7 +2836,7 @@ impl Workspace { cx.notify(); } - fn serialize_workspace(&self, cx: &AppContext) { + fn serialize_workspace(&self, cx: &ViewContext) { fn serialize_pane_handle( pane_handle: &ViewHandle, cx: &AppContext, @@ -2879,7 +2879,7 @@ impl Workspace { } } - fn build_serialized_docks(this: &Workspace, cx: &AppContext) -> DockStructure { + fn build_serialized_docks(this: &Workspace, cx: &ViewContext) -> DockStructure { let left_dock = this.left_dock.read(cx); let left_visible = left_dock.is_open(); let left_active_panel = left_dock.visible_panel().and_then(|panel| { @@ -2888,6 +2888,10 @@ impl Workspace { .to_string(), ) }); + let left_dock_zoom = left_dock + .visible_panel() + .map(|panel| panel.is_zoomed(cx)) + .unwrap_or(false); let right_dock = this.right_dock.read(cx); let right_visible = right_dock.is_open(); @@ -2897,6 +2901,11 @@ impl Workspace { .to_string(), ) }); + let right_dock_zoom = right_dock + .visible_panel() + .map(|panel| panel.is_zoomed(cx)) + .unwrap_or(false); + let bottom_dock = this.bottom_dock.read(cx); let bottom_visible = bottom_dock.is_open(); @@ -2906,19 +2915,27 @@ impl Workspace { .to_string(), ) }); + let bottom_dock_zoom = bottom_dock + .visible_panel() + .map(|panel| panel.is_zoomed(cx)) + .unwrap_or(false); + DockStructure { left: DockData { visible: left_visible, active_panel: left_active_panel, + zoom: left_dock_zoom }, right: DockData { visible: right_visible, active_panel: right_active_panel, + zoom: right_dock_zoom }, bottom: DockData { visible: bottom_visible, active_panel: bottom_active_panel, + zoom: bottom_dock_zoom }, } } @@ -3029,6 +3046,10 @@ impl Workspace { if let Some(active_panel) = docks.left.active_panel { if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { dock.activate_panel(ix, cx); + dock.active_panel() + .map(|panel| { + panel.set_zoomed(docks.left.zoom, cx) + }); } } }); @@ -3037,6 +3058,11 @@ impl Workspace { if let Some(active_panel) = docks.right.active_panel { if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { dock.activate_panel(ix, cx); + dock.active_panel() + .map(|panel| { + panel.set_zoomed(docks.right.zoom, cx) + }); + } } }); @@ -3045,6 +3071,11 @@ impl Workspace { if let Some(active_panel) = docks.bottom.active_panel { if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { dock.activate_panel(ix, cx); + dock.active_panel() + .map(|panel| { + panel.set_zoomed(docks.bottom.zoom, cx) + }); + } } }); From b9cb5946269ebd7ae9609b1b1198b6120f01aeaf Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 15 Jun 2023 14:51:38 -0700 Subject: [PATCH 3/5] Fix fmt --- crates/workspace/src/persistence/model.rs | 4 ++-- crates/workspace/src/workspace.rs | 26 +++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/workspace/src/persistence/model.rs b/crates/workspace/src/persistence/model.rs index 9a374907fb79bd678628e30e9b4d836d156f597c..10750618530642465d73eb3d4016e1d42095c85a 100644 --- a/crates/workspace/src/persistence/model.rs +++ b/crates/workspace/src/persistence/model.rs @@ -100,7 +100,7 @@ impl Bind for DockStructure { pub struct DockData { pub(crate) visible: bool, pub(crate) active_panel: Option, - pub(crate) zoom: bool + pub(crate) zoom: bool, } impl Column for DockData { @@ -112,7 +112,7 @@ impl Column for DockData { DockData { visible: visible.unwrap_or(false), active_panel, - zoom: zoom.unwrap_or(false) + zoom: zoom.unwrap_or(false), }, next_index, )) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index da10f6ecee76cd2e5026c434702a63ea14f83758..7d3aa17cf35227823cdb00c4f76fbb49c85add24 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2906,7 +2906,6 @@ impl Workspace { .map(|panel| panel.is_zoomed(cx)) .unwrap_or(false); - let bottom_dock = this.bottom_dock.read(cx); let bottom_visible = bottom_dock.is_open(); let bottom_active_panel = bottom_dock.visible_panel().and_then(|panel| { @@ -2920,22 +2919,21 @@ impl Workspace { .map(|panel| panel.is_zoomed(cx)) .unwrap_or(false); - DockStructure { left: DockData { visible: left_visible, active_panel: left_active_panel, - zoom: left_dock_zoom + zoom: left_dock_zoom, }, right: DockData { visible: right_visible, active_panel: right_active_panel, - zoom: right_dock_zoom + zoom: right_dock_zoom, }, bottom: DockData { visible: bottom_visible, active_panel: bottom_active_panel, - zoom: bottom_dock_zoom + zoom: bottom_dock_zoom, }, } } @@ -3046,24 +3044,25 @@ impl Workspace { if let Some(active_panel) = docks.left.active_panel { if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { dock.activate_panel(ix, cx); + } dock.active_panel() .map(|panel| { panel.set_zoomed(docks.left.zoom, cx) }); - } } }); + // TODO: I think the bug is that setting zoom or active undoes the bottom zoom or something workspace.right_dock.update(cx, |dock, cx| { dock.set_open(docks.right.visible, cx); if let Some(active_panel) = docks.right.active_panel { if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { dock.activate_panel(ix, cx); + + } dock.active_panel() .map(|panel| { panel.set_zoomed(docks.right.zoom, cx) }); - - } } }); workspace.bottom_dock.update(cx, |dock, cx| { @@ -3071,15 +3070,16 @@ impl Workspace { if let Some(active_panel) = docks.bottom.active_panel { if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { dock.activate_panel(ix, cx); - dock.active_panel() - .map(|panel| { - panel.set_zoomed(docks.bottom.zoom, cx) - }); - } } + + dock.active_panel() + .map(|panel| { + panel.set_zoomed(docks.bottom.zoom, cx) + }); }); + cx.notify(); })?; From b7e3ac5bf4e74ad2b82a25bf0764abb5631d2b13 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 15 Jun 2023 14:56:37 -0700 Subject: [PATCH 4/5] Fix bug on workspace deserialization --- crates/workspace/src/workspace.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 7d3aa17cf35227823cdb00c4f76fbb49c85add24..75820a8fbc99e21f8d20803c670f6bf876b6e934 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -3045,11 +3045,14 @@ impl Workspace { if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { dock.activate_panel(ix, cx); } + } dock.active_panel() .map(|panel| { panel.set_zoomed(docks.left.zoom, cx) }); - } + if docks.left.visible && docks.left.zoom { + cx.focus_self() + } }); // TODO: I think the bug is that setting zoom or active undoes the bottom zoom or something workspace.right_dock.update(cx, |dock, cx| { @@ -3059,11 +3062,15 @@ impl Workspace { dock.activate_panel(ix, cx); } + } dock.active_panel() .map(|panel| { panel.set_zoomed(docks.right.zoom, cx) }); - } + + if docks.right.visible && docks.right.zoom { + cx.focus_self() + } }); workspace.bottom_dock.update(cx, |dock, cx| { dock.set_open(docks.bottom.visible, cx); @@ -3077,6 +3084,10 @@ impl Workspace { .map(|panel| { panel.set_zoomed(docks.bottom.zoom, cx) }); + + if docks.bottom.visible && docks.bottom.zoom { + cx.focus_self() + } }); From b156644daf92e51035a6ccd483e86df495560411 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 15 Jun 2023 15:09:37 -0700 Subject: [PATCH 5/5] fixed tests to match new behavior --- crates/workspace/src/workspace.rs | 4 ++-- crates/zed/src/zed.rs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 75820a8fbc99e21f8d20803c670f6bf876b6e934..5a5e5686f70b0109c6205ca822eb89f93a88b6d5 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -4453,7 +4453,7 @@ mod tests { workspace.read_with(cx, |workspace, cx| { assert!(workspace.right_dock().read(cx).is_open()); assert!(!panel.is_zoomed(cx)); - assert!(!panel.has_focus(cx)); + assert!(panel.has_focus(cx)); }); // Focus and zoom panel @@ -4528,7 +4528,7 @@ mod tests { workspace.read_with(cx, |workspace, cx| { let pane = pane.read(cx); assert!(!pane.is_zoomed()); - assert!(pane.has_focus()); + assert!(!pane.has_focus()); assert!(workspace.right_dock().read(cx).is_open()); assert!(workspace.zoomed.is_none()); }); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 088d26be78ad3048fba5516ac3f67eb3f846d600..bcdfe57a469013251994b4112500daa4a7489027 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -384,6 +384,8 @@ pub fn initialize_workspace( workspace.toggle_dock(project_panel_position, cx); } + cx.focus_self(); + workspace.add_panel(terminal_panel, cx); if let Some(assistant_panel) = assistant_panel { workspace.add_panel(assistant_panel, cx);