From 32e96e126f5e31cd23d621a584203edbfb692a83 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Fri, 30 Aug 2024 11:54:46 +0200 Subject: [PATCH] workspace: Ensure last_active_center_pane is updated on focus (#17140) This fixes a bug that I've been running into for quite a while: - Open a new terminal inside Zed - (Center pane loses focus) - (Workspace is serialized) - Quit Zed - Open Zed - (Workspace is deserialized without an active pane) - Put cursor in assistant panel - Try to use `ActivatePaneInDirection` to go to the center - Does not work So what this fix does is to ensure that in case the pane does become focused, even though it was already marked as focused, the active center pane is set. It also adds a fallback when trying to get the last active pane. Release Notes: - Fixed an issue where `workspace::ActivatePaneInDirection` could not activate the center pane (i.e. one couldn't navigate from terminal or assistant panel to the center pane) after loading Zed. --- crates/workspace/src/workspace.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 92014d624227f9e5e9cfe40fb3c28d56210ccf2c..b3904ce44db177af0cbae321663a154ec96fd112 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2801,10 +2801,17 @@ impl Workspace { .unwrap_or(Origin::Center); let get_last_active_pane = || { - self.last_active_center_pane.as_ref().and_then(|p| { - let p = p.upgrade()?; - (p.read(cx).items_len() != 0).then_some(p) - }) + let pane = self + .last_active_center_pane + .clone() + .unwrap_or_else(|| { + self.panes + .first() + .expect("There must be an active pane") + .downgrade() + }) + .upgrade()?; + (pane.read(cx).items_len() != 0).then_some(pane) }; let try_dock = @@ -2924,6 +2931,10 @@ impl Workspace { self.last_active_center_pane = Some(pane.downgrade()); } + if self.last_active_center_pane.is_none() { + self.last_active_center_pane = Some(pane.downgrade()); + } + self.dismiss_zoomed_items_to_reveal(None, cx); if pane.read(cx).is_zoomed() { self.zoomed = Some(pane.downgrade().into());