# picker: Automatically switch layout depending on window dimensions \(\#60559\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 01f915d6be2b7fff98ba21a62e7e7181a2758f57

Requested commit: 01f915d6be2b7fff98ba21a62e7e7181a2758f57

Commit: 01f915d6be2b7fff98ba21a62e7e7181a2758f57

Tree: bef9aa3c32dc2c1846f8192c9bd5af5ecb71bd11

Author: Zephiris Evergreen

Committer: GitHub

## Message

```
picker: Automatically switch layout depending on window dimensions (#60559)

# 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:

- [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
```

## Parents

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

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