theme_selector: Revert theme when modal is dismissed by clicking outside (#52773)

Context

Related to #52118

Found this while looking into the theme selector filtering bug: clicking
outside the theme selector (or icon theme selector) keeps the previewed
theme applied instead of reverting. `hide_modal()` doesn't go through
the Picker's `dismissed()` callback, so the in-memory theme override
sticks around without being written to `settings.json`.

This PR only fixes the click-outside behavior. The filtering issue from
#52118 is separate.

## Demo

**Before (bug):**


https://github.com/user-attachments/assets/f8be49c4-7e1d-483c-bf23-346022ac83aa



**After (fix):**



https://github.com/user-attachments/assets/29cc1740-c869-42d1-8aee-fe46a091a949



## How to review

Two files, symmetrical changes. Look at:
- `on_before_dismiss` in `theme_selector.rs` and
`icon_theme_selector.rs`
- The extracted `revert_theme()` method on both delegates, now shared
between `dismissed()` and `on_before_dismiss`

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] 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)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


Release Notes:

- Fixed theme selector keeping the previewed theme when clicking outside
instead of reverting to the original.
This commit is contained in:
João Soares 2026-04-23 08:36:03 -03:00 committed by GitHub
parent b830524713
commit 16466ea936
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 12 deletions

View file

@ -26,7 +26,18 @@ impl Focusable for IconThemeSelector {
}
}
impl ModalView for IconThemeSelector {}
impl ModalView for IconThemeSelector {
fn on_before_dismiss(
&mut self,
_window: &mut Window,
cx: &mut Context<Self>,
) -> workspace::DismissDecision {
self.picker.update(cx, |picker, cx| {
picker.delegate.revert_theme(cx);
});
workspace::DismissDecision::Dismiss(true)
}
}
impl IconThemeSelector {
pub fn new(
@ -132,6 +143,13 @@ impl IconThemeSelectorDelegate {
.unwrap_or(self.selected_index);
}
fn revert_theme(&mut self, cx: &mut App) {
if !self.selection_completed {
Self::set_icon_theme(self.original_theme.clone(), cx);
self.selection_completed = true;
}
}
fn set_icon_theme(name: IconThemeName, cx: &mut App) {
SettingsStore::update_global(cx, |store, _| {
let mut theme_settings = store.get::<ThemeSettings>(None).clone();
@ -185,10 +203,7 @@ impl PickerDelegate for IconThemeSelectorDelegate {
}
fn dismissed(&mut self, _: &mut Window, cx: &mut Context<Picker<IconThemeSelectorDelegate>>) {
if !self.selection_completed {
Self::set_icon_theme(self.original_theme.clone(), cx);
self.selection_completed = true;
}
self.revert_theme(cx);
self.selector
.update(cx, |_, cx| cx.emit(DismissEvent))

View file

@ -79,7 +79,18 @@ fn toggle_icon_theme_selector(
});
}
impl ModalView for ThemeSelector {}
impl ModalView for ThemeSelector {
fn on_before_dismiss(
&mut self,
_window: &mut Window,
cx: &mut Context<Self>,
) -> workspace::DismissDecision {
self.picker.update(cx, |picker, cx| {
picker.delegate.revert_theme(cx);
});
workspace::DismissDecision::Dismiss(true)
}
}
struct ThemeSelector {
picker: Entity<Picker<ThemeSelectorDelegate>>,
@ -215,6 +226,15 @@ impl ThemeSelectorDelegate {
}
}
fn revert_theme(&mut self, cx: &mut App) {
if !self.selection_completed {
SettingsStore::update_global(cx, |store, _| {
store.override_global(self.original_theme_settings.clone());
});
self.selection_completed = true;
}
}
fn set_theme(&mut self, new_theme: Arc<Theme>, cx: &mut App) {
// Update the global (in-memory) theme settings.
SettingsStore::update_global(cx, |store, _| {
@ -371,12 +391,7 @@ impl PickerDelegate for ThemeSelectorDelegate {
}
fn dismissed(&mut self, _: &mut Window, cx: &mut Context<Picker<ThemeSelectorDelegate>>) {
if !self.selection_completed {
SettingsStore::update_global(cx, |store, _| {
store.override_global(self.original_theme_settings.clone());
});
self.selection_completed = true;
}
self.revert_theme(cx);
self.selector
.update(cx, |_, cx| cx.emit(DismissEvent))