Skip to content

Fix expand/collapse all button for splittable editor#50859

Merged
dinocosta merged 9 commits intomainfrom
split-diff-expand-collapse-fix
Mar 9, 2026
Merged

Fix expand/collapse all button for splittable editor#50859
dinocosta merged 9 commits intomainfrom
split-diff-expand-collapse-fix

Conversation

@dinocosta
Copy link
Copy Markdown
Member

@dinocosta dinocosta commented Mar 5, 2026

The "Expand All Files"/"Collapse All Files" button in BufferSearchBar was broken for SplittableEditor, which is used in the project diff view. It was happening because ProjectDiff::as_searchable returns an handle to the SplittableEditor, which the search bar implementation then tries to downcast to an Editor, which the SplittableEditor did not support, so both the expand/collapse all buttons, as well as the collapse state were broken.

Unfortunately this was accidentally introduced in #48773 , so this Pull Request updates the Item implementation for SplittableEditor in order for it to be able to act as an Editor.

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Release Notes:

  • Fix the "Expand All Files"/"Collapse All Files" button in the project diff view

dinocosta and others added 4 commits March 5, 2026 15:48
We were downcasting just to `Editor`, without taking into account that
we might be handling a `SplittableEditor`. Might want to refactor this
in a way that doesn't involve downcasting.

Co-authored-by: Tom Houlé <tom@tomhoule.com>
Same thing as previous commit, we were downcasting to `Editor` only,
while we also need to handle `SplittableEditor`.

Co-authored-by: Tom Houlé <tom@tomhoule.com>
Refactor the approach of downcasting the
`BufferSearchBar::active_searchable_item` to either an `Editor` or
`SplittableEditor` in order to fold or unfold all excerpts, to a more
explicit `FoldableItem` trait.

This way we avoid downcasting, we'll still need to update tests in a
future commit.

Co-authored-by: Tom Houlé <tom@tomhoule.com>
- Remove default `impl` on `CollapsibleItem::has_any_folded` to force
  implementors to provide it explicitly
- Change `has_any_collapsed` to take `&App` instead of `&Context<Self>`,
  use `read`() instead of `update`() in the blanket `impl`
- Move `CollapsibleItem`/`CollapsibleItemHandle` from `searchable.rs` to
  `collapsible.rs`
- Add missing `as_collapsible` implementations for
  `ProjectDiagnosticsEditor`, `AgentDiffPane`, `CommitView`,
  `MultiDiffView` and `TextDiffView`
- Guard `needs_expand_collapse_option` on `active_collapsible_item`
  presence in order to prevent the expand/collapse all button from being
  shown if the buffer search bar does not have a collapsible item handle
- Inline `rhs_editor` delegation in `SplittableEditor`'s `CollapsibleItem`
  impl

As a note, tests still might need to be updated eventually to better
test this `CollapsibleItemHandle` path.

Co-authored-by: Tom Houlé <tom@tomhoule.com>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 5, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Mar 5, 2026
@dinocosta dinocosta changed the title search: Fix and refactor expand/collapse all button Fix and refactor expand/collapse all button in buffer search bar Mar 5, 2026
@dinocosta
Copy link
Copy Markdown
Member Author

A quick screen recording of the before and after of the button's behavior in the Git Diff view, for comparison ▼

Before

CleanShot.2026-03-05.at.20.41.06.mp4

After

CleanShot.2026-03-05.at.20.40.23.mp4

@dinocosta dinocosta self-assigned this Mar 5, 2026
Bundle the searchable and collapsible item handles into an `ActiveItem`
struct so they are always set and cleared atomically. Add
`searchable()`, `collapsible()`, and `collapsible_mut()` accessor
methods on `BufferSearchBar` to reduce direct field access. Replace all
`active_searchable_item` and `active_collapsible_item` field references
with the new struct and accessors.
@dinocosta dinocosta force-pushed the split-diff-expand-collapse-fix branch from c43b17f to 11fd436 Compare March 6, 2026 14:38
Revert changes introduced so far in order to explore updating
`SplittableEditor`'s implementation of the `Item` trait, to make it able
to act as an `Editor`.
@dinocosta dinocosta force-pushed the split-diff-expand-collapse-fix branch from 4eb379e to 9f50c8f Compare March 9, 2026 14:45
Update the `workspace::item::Item` trait implementation for
`editor::split::SplittableEditor` to ensure that it can act as an
`editor::Editor`.

This fixes a bug where the all files expand/collapse button was not
working on the project diff view. Since the `ProjectDiff::as_searchable`
implementation returns an handle to the `SplittableEditor`, whenever the
`BufferSearchBar` tried to downcast the handle to an `Editor`, this
would silently fail.
@dinocosta dinocosta force-pushed the split-diff-expand-collapse-fix branch from 9f50c8f to e096443 Compare March 9, 2026 14:45
@dinocosta dinocosta changed the title Fix and refactor expand/collapse all button in buffer search bar Fix expand/collapse all button for splittable editor Mar 9, 2026
@dinocosta dinocosta marked this pull request as ready for review March 9, 2026 17:43
@dinocosta dinocosta merged commit fbeffc4 into main Mar 9, 2026
31 checks passed
@dinocosta dinocosta deleted the split-diff-expand-collapse-fix branch March 9, 2026 17:45
@dinocosta
Copy link
Copy Markdown
Member Author

/cherry-pick preview

github-actions bot pushed a commit that referenced this pull request Mar 9, 2026
The "Expand All Files"/"Collapse All Files" button in `BufferSearchBar`
was broken for `SplittableEditor`, which is used in the project diff
view. It was happening because `ProjectDiff::as_searchable` returns an
handle to the `SplittableEditor`, which the search bar implementation
then tries to downcast to an `Editor`, which the `SplittableEditor` did
not support, so both the expand/collapse all buttons, as well as the
collapse state were broken.

Unfortunately this was accidentally introduced in
#48773 , so this Pull Request
updates the `Item` implementation for `SplittableEditor` in order for it
to be able to act as an `Editor`.

Release Notes:

- Fix the "Expand All Files"/"Collapse All Files" button in the project
diff view

---------

Co-authored-by: Tom Houlé <tom@tomhoule.com>
zed-zippy bot added a commit that referenced this pull request Mar 9, 2026
…-pick to preview) (#51124)

Cherry-pick of #50859 to preview

----
The "Expand All Files"/"Collapse All Files" button in `BufferSearchBar`
was broken for `SplittableEditor`, which is used in the project diff
view. It was happening because `ProjectDiff::as_searchable` returns an
handle to the `SplittableEditor`, which the search bar implementation
then tries to downcast to an `Editor`, which the `SplittableEditor` did
not support, so both the expand/collapse all buttons, as well as the
collapse state were broken.

Unfortunately this was accidentally introduced in
#48773 , so this Pull Request
updates the `Item` implementation for `SplittableEditor` in order for it
to be able to act as an `Editor`.

Release Notes:

- Fix the "Expand All Files"/"Collapse All Files" button in the project
diff view

---------

Co-authored-by: Tom Houlé <tom@tomhoule.com>

Co-authored-by: Dino <dinojoaocosta@gmail.com>
Co-authored-by: Tom Houlé <tom@tomhoule.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant