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.
This commit is contained in:
Thorsten Ball 2024-08-30 11:54:46 +02:00 committed by GitHub
parent 820ad488e4
commit 32e96e126f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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());