Skip to content

picker: Automatically switch layout depending on window dimensions - #60559

Merged
yara-blue merged 2 commits into
zed-industries:mainfrom
zphrs:59820
Jul 10, 2026
Merged

picker: Automatically switch layout depending on window dimensions#60559
yara-blue merged 2 commits into
zed-industries:mainfrom
zphrs:59820

Conversation

@zphrs

@zphrs zphrs commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Objective

Fixes #59820.

Solution

At a high level, I approached this by conditionally rendering a Below preview layout only when the preview was at or below the min width of the Right when the layout is Right. Since there's one breakpoint at SizeBounds::min_width() and hitting that breakpoint only changes rendering (and doesn't change the state), there's no need to persist to storage or memory that the view is forced to be Below.

I toggled between the two rendering modes by defining Picker::preview_layout_rendered() that would return Below if the window was equal to or smaller than its min width. Then I replaced all calls of preview_layout() that used the response purely for rendering purposes with preview_layout_rendered(). I avoided replacing preview_layout() calls that were responsible for persisting the current layout and window dimensions to disk to ensure that changes to the window dimensions were properly synced to the correct layout. This way changes to the window while in the BelowAuto rendering mode edit the Right window dimensions on disk.

Testing

I tested these changes manually with the following actions on my local machine (an Apple Silicon Macbook Pro):

  • resizing the popover
  • resizing the window
  • adjusting the split
  • making sure the popover size and split percent remains the same after:
    • closing and re-opening the popover
    • closing and re-opening the application and making sure the window size and split percent remains the same

Reviewers can test my changes by performing the same manual actions.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Showcase

Before

old.mov

After

new.mov

Release Notes:

  • fix(picker): Automatically switch from Right split to Down split when picker gets too narrow

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 7, 2026
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Jul 7, 2026
@zphrs zphrs changed the title Implementation of https://github.com/zed-industries/zed/issues/59820. Picker: Automatically switch layout depending on window dimensions Jul 7, 2026
@maxdeviant maxdeviant changed the title Picker: Automatically switch layout depending on window dimensions picker: Automatically switch layout depending on window dimensions Jul 7, 2026
Comment thread crates/picker/src/preview.rs Outdated
Comment thread crates/picker/src/render.rs Outdated
Comment thread crates/picker/src/shape.rs
@zphrs
zphrs marked this pull request as ready for review July 8, 2026 02:22
@dinocosta dinocosta added the area:pickers Everything related to pickers that are in a modal label Jul 8, 2026
@zphrs

zphrs commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

I used the min width of the preview in order to determine when to switch and I left the minimum at the current value of 8rem. It might be a good idea to set this value to be higher than 8rem. For instance, the git diff split view has the default minimum of 100 total for it to allow using the split view. If this is a reasonable preference for diffs, then setting the minimum preview width to 50rem to allow using the Right split picker would align with the minimum used for the right-split git diff.

@yara-blue

Copy link
Copy Markdown
Contributor

Thank you! :3

The use case I had in mind was changing the Zed window size. But I think this works for that as well right?

Might be an idea to gray out the button when a layout is not available and we auto switched. What do you think? That might be a good way to "explain" to the user what is happening.

@zphrs

zphrs commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Thank you! :3

Sure! It was a fun first issue, thank you for writing it up and labeling it as such.

The use case I had in mind was changing the Zed window size. But I think this works for that as well right?

Yes, it does work for narrow windows as well because the popover gets narrower when the window gets too narrow.

Might be an idea to gray out the button when a layout is not available and we auto switched. What do you think? That might be a good way to "explain" to the user what is happening.

I didn’t grey it out to align with the behavior of the git diff that keeps it blue with a cross through it.
git diff icons in the auto mode

I personally like with the git diff behavior with keeping it blue because it indicates to the user they’re in the “vertical auto” split mode that will automatically switch back if they make the popover wide enough.

Happy to change it to be grey, just figured I’d mention my reasoning behind keeping it blue.

@yara-blue
yara-blue added this pull request to the merge queue Jul 10, 2026
@yara-blue

Copy link
Copy Markdown
Contributor

Happy to change it to be grey, just figured I’d mention my reasoning behind keeping it blue.

You convinced me :)

And our designer can always tweak it if they want it slightly different

lets merge this!

Merged via the queue into zed-industries:main with commit 01f915d Jul 10, 2026
51 checks passed
@zed-zippy zed-zippy Bot added the PR state:needs review Used to label PRs that are in need of a post-merge approval label Jul 10, 2026
@yara-blue

Copy link
Copy Markdown
Contributor

@zed-industries/approved

@zed-zippy zed-zippy Bot removed the PR state:needs review Used to label PRs that are in need of a post-merge approval label Jul 10, 2026
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…ed-industries#60559)

# Objective

Fixes zed-industries#59820. 

## Solution

At a high level, I approached this by conditionally rendering a `Below`
preview layout only when the preview was at or below the min width of
the `Right` when the layout is `Right`. Since there's one breakpoint at
`SizeBounds::min_width()` and hitting that breakpoint only changes
rendering (and doesn't change the state), there's no need to persist to
storage or memory that the view is forced to be Below.

I toggled between the two rendering modes by defining
`Picker::preview_layout_rendered()` that would return `Below` if the
window was equal to or smaller than its min width. Then I replaced all
calls of `preview_layout()` that used the response purely for rendering
purposes with `preview_layout_rendered()`. I avoided replacing
`preview_layout()` calls that were responsible for persisting the
current layout and window dimensions to disk to ensure that changes to
the window dimensions were properly synced to the correct layout. This
way changes to the window while in the `BelowAuto` rendering mode edit
the `Right` window dimensions on disk.

## Testing

I tested these changes manually with the following actions on my local
machine (an Apple Silicon Macbook Pro):
- resizing the popover
- resizing the window
- adjusting the split
- making sure the popover size and split percent remains the same after:
  - closing and re-opening the popover
- closing and re-opening the application and making sure the window size
and split percent remains the same
  
Reviewers can test my changes by performing the same manual actions.

## Self-Review Checklist:

- [X] I've reviewed my own diff for quality, security, and reliability
- [X] Unsafe blocks (if any) have justifying comments
- [X] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [X] Tests cover the new/changed behavior
- [X] Performance impact has been considered and is acceptable

## Showcase

### Before


https://github.com/user-attachments/assets/a4524065-d1a3-4595-bc9e-50c9715b4e66

### After


https://github.com/user-attachments/assets/fede7eb0-5d73-423c-8df0-8192caee8d26

---

Release Notes:

- fix(picker): Automatically switch from Right split to Down split when
picker gets too narrow
playdohface pushed a commit to playdohface/zed that referenced this pull request Aug 29, 2026
…ed-industries#60559)

# Objective

Fixes zed-industries#59820. 

## Solution

At a high level, I approached this by conditionally rendering a `Below`
preview layout only when the preview was at or below the min width of
the `Right` when the layout is `Right`. Since there's one breakpoint at
`SizeBounds::min_width()` and hitting that breakpoint only changes
rendering (and doesn't change the state), there's no need to persist to
storage or memory that the view is forced to be Below.

I toggled between the two rendering modes by defining
`Picker::preview_layout_rendered()` that would return `Below` if the
window was equal to or smaller than its min width. Then I replaced all
calls of `preview_layout()` that used the response purely for rendering
purposes with `preview_layout_rendered()`. I avoided replacing
`preview_layout()` calls that were responsible for persisting the
current layout and window dimensions to disk to ensure that changes to
the window dimensions were properly synced to the correct layout. This
way changes to the window while in the `BelowAuto` rendering mode edit
the `Right` window dimensions on disk.

## Testing

I tested these changes manually with the following actions on my local
machine (an Apple Silicon Macbook Pro):
- resizing the popover
- resizing the window
- adjusting the split
- making sure the popover size and split percent remains the same after:
  - closing and re-opening the popover
- closing and re-opening the application and making sure the window size
and split percent remains the same
  
Reviewers can test my changes by performing the same manual actions.

## Self-Review Checklist:

- [X] I've reviewed my own diff for quality, security, and reliability
- [X] Unsafe blocks (if any) have justifying comments
- [X] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [X] Tests cover the new/changed behavior
- [X] Performance impact has been considered and is acceptable

## Showcase

### Before


https://github.com/user-attachments/assets/a4524065-d1a3-4595-bc9e-50c9715b4e66

### After


https://github.com/user-attachments/assets/fede7eb0-5d73-423c-8df0-8192caee8d26

---

Release Notes:

- fix(picker): Automatically switch from Right split to Down split when
picker gets too narrow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:pickers Everything related to pickers that are in a modal cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Picker: Automatically switch layout depending on window dimensions

3 participants