Skip to content

theme_selector: Preserve selected theme after empty filter#52461

Merged
osiewicz merged 1 commit intozed-industries:mainfrom
Dnreikronos:fix/theme-selector-preserve-selection-on-empty-filter
Apr 7, 2026
Merged

theme_selector: Preserve selected theme after empty filter#52461
osiewicz merged 1 commit intozed-industries:mainfrom
Dnreikronos:fix/theme-selector-preserve-selection-on-empty-filter

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

When filtering themes with a query that matches nothing (e.g., "zzz"), show_selected_theme returned None and overwrote selected_theme. Clearing the filter then lost track of the previous selection and defaulted to index 0.

The fix only updates selected_theme when show_selected_theme returns Some. Same change in both the theme selector and the icon theme selector.

Context

When update_matches runs a filter that yields zero results, show_selected_theme returns None. The old code unconditionally assigned that back to selected_theme, wiping out the previous selection. When the user clears the filter, the selector falls into the query.is_empty() && selected_theme.is_none() branch and resets to index 0 instead of restoring the original pick.

Demo

Before:

before_theme.mp4

After:

2026-03-22.13-54-20.mp4

How to review

The fix is the same one-line change in two files:

  1. crates/theme_selector/src/theme_selector.rs — line 458
  2. crates/theme_selector/src/icon_theme_selector.rs — line 272

The rest is test infrastructure:
3. crates/theme/src/registry.rsregister_test_themes / register_test_icon_themes helpers
4. Tests in both selector files covering the empty filter → clear filter flow

Self-review checklist

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

Release notes

  • Fixed theme selector losing the selected theme after filtering with a query that matches nothing and then clearing the filter.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Mar 26, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator Bot requested review from a team, Anthony-Eid and osiewicz and removed request for a team March 26, 2026 01:16
@osiewicz
Copy link
Copy Markdown
Member

Thanks! Sans conflicts, this looks good to me.

@zed-industries-bot
Copy link
Copy Markdown
Contributor

zed-industries-bot commented Mar 30, 2026

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against 5c965ac

@Dnreikronos Dnreikronos force-pushed the fix/theme-selector-preserve-selection-on-empty-filter branch 2 times, most recently from 8cf7ade to cd3728c Compare March 30, 2026 14:37
@Dnreikronos
Copy link
Copy Markdown
Contributor Author

Hi @osiewicz,
I just adjusted the conflicts. Can you run the CI/CD pipelines again, please?

When filtering themes with a query that matches nothing (e.g., "zzz"),
show_selected_theme` returned `None` and overwrote `selected_theme`.
Clearing the filter then lost track of the previous selection and
defaulted to index 0. Guard the assignment so `selected_theme` is only
updated when `show_selected_theme` returns `Some`.
@Dnreikronos Dnreikronos force-pushed the fix/theme-selector-preserve-selection-on-empty-filter branch from cd3728c to 5c965ac Compare March 30, 2026 22:29
@Dnreikronos Dnreikronos requested a review from osiewicz March 31, 2026 12:37
@Dnreikronos
Copy link
Copy Markdown
Contributor Author

Hi @osiewicz!
I adjusted the CI pipeline error. Can you, please, trigger the process again?

@osiewicz
Copy link
Copy Markdown
Member

osiewicz commented Apr 7, 2026

Yup, sorry for being MIA

@osiewicz osiewicz enabled auto-merge (squash) April 7, 2026 23:20
@osiewicz osiewicz merged commit 972731c into zed-industries:main Apr 7, 2026
30 checks passed
piper-of-dawn pushed a commit to piper-of-dawn/zed that referenced this pull request Apr 25, 2026
…tries#52461)

When filtering themes with a query that matches nothing (e.g., "zzz"),
`show_selected_theme` returned `None` and overwrote `selected_theme`.
Clearing the filter then lost track of the previous selection and
defaulted to index 0.

The fix only updates `selected_theme` when `show_selected_theme` returns
`Some`. Same change in both the theme selector and the icon theme
selector.

## Context

When `update_matches` runs a filter that yields zero results,
`show_selected_theme` returns `None`. The old code unconditionally
assigned that back to `selected_theme`, wiping out the previous
selection. When the user clears the filter, the selector falls into the
`query.is_empty() && selected_theme.is_none()` branch and resets to
index 0 instead of restoring the original pick.

## Demo

### Before:


https://github.com/user-attachments/assets/62b1531b-d059-4f30-b1f4-a830f2d13a09


### After:



https://github.com/user-attachments/assets/72348666-8dbb-4f35-9446-fa2618340b6c




## How to review

The fix is the same one-line change in two files:
1. `crates/theme_selector/src/theme_selector.rs` — line 458
2. `crates/theme_selector/src/icon_theme_selector.rs` — line 272

The rest is test infrastructure:
3. `crates/theme/src/registry.rs` — `register_test_themes` /
`register_test_icon_themes` helpers
4. Tests in both selector files covering the empty filter → clear filter
flow

## 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 is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

## Release notes

- Fixed theme selector losing the selected theme after filtering with a
query that matches nothing and then clearing the filter.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants