Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
theme_selector: Revert theme when modal is dismissed by clicking outside (#52773)
João Soares16466ea93667
diff --git a/crates/theme_selector/src/icon_theme_selector.rs b/crates/theme_selector/src/icon_theme_selector.rsindex be8e5e01d0a..725881f8cc1 100644--- a/crates/theme_selector/src/icon_theme_selector.rs+++ b/crates/theme_selector/src/icon_theme_selector.rs@@ -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))diff --git a/crates/theme_selector/src/theme_selector.rs b/crates/theme_selector/src/theme_selector.rsindex 8a0e835fa86..c60218003df 100644--- a/crates/theme_selector/src/theme_selector.rs+++ b/crates/theme_selector/src/theme_selector.rs@@ -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))