# project_panel: Collapse top-level entries in \`Collapse all entries\` command \(\#38310\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/50326ddc359e612e9f91cffa64565f87bc814d0a)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 50326ddc359e612e9f91cffa64565f87bc814d0a

Requested commit: 50326ddc359e612e9f91cffa64565f87bc814d0a

Commit: 50326ddc359e612e9f91cffa64565f87bc814d0a

Tree: 2762d92c14b855bf6693b04319a195ee96b443ee

Author: Nils Koch

Committer: GitHub

## Message

```
project_panel: Collapse top-level entries in `Collapse all entries` command (#38310)

Closes #11760

The command `project panel: collapse all entries` currently does not
collapse top-level entries (the workspaces themselves). I think this
should be expected behaviour if you only have a single workspace in your
project. However, if you have multiple workspaces, we should collapse
their top-level folders as well. This is the expected behaviour in the
screenshots in #11760.

For more context: Atm the `.retain` function empties the
`self.expanded_dir_ids` Hash Map, because the `expanded_entries` Vec is
(almost) never empty - it contains the id of the `root_entry` of the
workspace.


https://github.com/zed-industries/zed/blob/d48d6a745409a8998998ed59c28493a1aa733ebb/crates/project_panel/src/project_panel.rs#L1148-L1152

We then update the `self.expanded_dir_ids` in the
`update_visible_entries` function, and since the Hash Map is empty, we
execute the `hash_map::Entry::Vacant` arm of the following match
statement.


https://github.com/zed-industries/zed/blob/d48d6a745409a8998998ed59c28493a1aa733ebb/crates/project_panel/src/project_panel.rs#L3062-L3073

This change makes sure that we do not clear the `expanded_dir_ids`
HashMap and always keep the keys for all visible workspaces and
therefore we run the `hash_map::Entry::Occupied` arm, which does not
override the `expanded_dir_ids` anymore.



https://github.com/user-attachments/assets/b607523b-2ea2-4159-8edf-aed7bca05e3a

cc @MrSubidubi 

Release Notes:

- N/A *or* Added/Fixed/Improved ...

---------

Co-authored-by: Finn Evers <finn.evers@outlook.de>
```

## Parents

- [52521efc7b898ad0431810ecb89660129bf11dfe](https://git.cafe/gitcafe/zed/commit/52521efc7b898ad0431810ecb89660129bf11dfe?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/50326ddc359e612e9f91cffa64565f87bc814d0a?format=markdown)
