# theme_selector: Preserve selected theme after empty filter \(\#52461\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 972731cb1a1c971a947dc28a90c0d3c20c09996a

Requested commit: 972731cb1a1c971a947dc28a90c0d3c20c09996a

Commit: 972731cb1a1c971a947dc28a90c0d3c20c09996a

Tree: 7fd2eafdb0b882187787b215888b4cfdcb852fe8

Author: João Soares

Committer: GitHub

## Message

```
theme_selector: Preserve selected theme after empty filter (#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.
```

## Parents

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

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