theme_selector: Preserve selected theme after empty filter#52461
Merged
osiewicz merged 1 commit intozed-industries:mainfrom Apr 7, 2026
Merged
Conversation
5 tasks
osiewicz
approved these changes
Mar 30, 2026
Member
|
Thanks! Sans conflicts, this looks good to me. |
Contributor
8cf7ade to
cd3728c
Compare
Contributor
Author
|
Hi @osiewicz, |
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`.
cd3728c to
5c965ac
Compare
Contributor
Author
|
Hi @osiewicz! |
Member
|
Yup, sorry for being MIA |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When filtering themes with a query that matches nothing (e.g., "zzz"),
show_selected_themereturnedNoneand overwroteselected_theme. Clearing the filter then lost track of the previous selection and defaulted to index 0.The fix only updates
selected_themewhenshow_selected_themereturnsSome. Same change in both the theme selector and the icon theme selector.Context
When
update_matchesruns a filter that yields zero results,show_selected_themereturnsNone. The old code unconditionally assigned that back toselected_theme, wiping out the previous selection. When the user clears the filter, the selector falls into thequery.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:
crates/theme_selector/src/theme_selector.rs— line 458crates/theme_selector/src/icon_theme_selector.rs— line 272The rest is test infrastructure:
3.
crates/theme/src/registry.rs—register_test_themes/register_test_icon_themeshelpers4. Tests in both selector files covering the empty filter → clear filter flow
Self-review checklist
Release notes