Prevent folder expansion when all items are closed (#12729)

Release Notes:

- Prevent folder expansion when all items are closed

### Problem
When all items are closed, the next activated file expands (see the
video below).


https://github.com/zed-industries/zed/assets/21101490/a7631cd2-4e97-4954-8b01-d283dd4796be


### Cause
When the currently active item is closed, Zed tries to activate the
previously active item. Activating an item by default expands the
corresponding folder, which can result in folders being expanded when
all files are closed.

### Fixed Video


https://github.com/zed-industries/zed/assets/21101490/d30f05c5-6d86-4e11-b349-337fa75586f3
This commit is contained in:
Panghu 2024-06-07 00:32:58 +09:00 committed by GitHub
parent 0c7e745be8
commit fd39f20842
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1133,11 +1133,19 @@ impl Pane {
} }
} }
// If a buffer is open both in a singleton editor and in a multibuffer, make sure let active_item_id = self.active_item().map(|item| item.item_id());
// to focus the singleton buffer when prompting to save that buffer, as opposed
// to focusing the multibuffer, because this gives the user a more clear idea items_to_close.sort_by_key(|item| {
// of what content they would be saving. // Put the currently active item at the end, because if the currently active item is not closed last
items_to_close.sort_by_key(|item| !item.is_singleton(cx)); // closing the currently active item will cause the focus to switch to another item
// This will cause Zed to expand the content of the currently active item
active_item_id.filter(|&id| id == item.item_id()).is_some()
// If a buffer is open both in a singleton editor and in a multibuffer, make sure
// to focus the singleton buffer when prompting to save that buffer, as opposed
// to focusing the multibuffer, because this gives the user a more clear idea
// of what content they would be saving.
|| !item.is_singleton(cx)
});
let workspace = self.workspace.clone(); let workspace = self.workspace.clone();
cx.spawn(|pane, mut cx| async move { cx.spawn(|pane, mut cx| async move {