From 8f262892a04fedb1585f1d06785f9f699678eb41 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 15 Jan 2024 14:53:24 -0800 Subject: [PATCH 1/4] Notify editors on buffer font size changes --- crates/editor/src/editor.rs | 7 ++++++- crates/theme/src/settings.rs | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 288d25f9cd..ce9c4215cc 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -97,7 +97,10 @@ use std::{ pub use sum_tree::Bias; use sum_tree::TreeMap; use text::{OffsetUtf16, Rope}; -use theme::{ActiveTheme, PlayerColor, StatusColors, SyntaxTheme, ThemeColors, ThemeSettings}; +use theme::{ + observe_buffer_font_size_adjustment, ActiveTheme, PlayerColor, StatusColors, SyntaxTheme, + ThemeColors, ThemeSettings, +}; use ui::{ h_flex, prelude::*, ButtonSize, ButtonStyle, IconButton, IconName, IconSize, ListItem, Popover, Tooltip, @@ -1812,6 +1815,7 @@ impl Editor { cx.observe(&display_map, Self::on_display_map_changed), cx.observe(&blink_manager, |_, _, cx| cx.notify()), cx.observe_global::(Self::settings_changed), + observe_buffer_font_size_adjustment(cx, |_, cx| cx.notify()), cx.observe_window_activation(|editor, cx| { let active = cx.is_window_active(); editor.blink_manager.update(cx, |blink_manager, cx| { @@ -8741,6 +8745,7 @@ impl Editor { )), cx, ); + cx.notify(); } pub fn set_searchable(&mut self, searchable: bool) { diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs index e51ff81b01..efc62ed59c 100644 --- a/crates/theme/src/settings.rs +++ b/crates/theme/src/settings.rs @@ -1,7 +1,9 @@ use crate::one_themes::one_dark; use crate::{Theme, ThemeRegistry}; use anyhow::Result; -use gpui::{px, AppContext, Font, FontFeatures, FontStyle, FontWeight, Pixels}; +use gpui::{ + px, AppContext, Font, FontFeatures, FontStyle, FontWeight, Pixels, Subscription, ViewContext, +}; use schemars::{ gen::SchemaGenerator, schema::{InstanceType, Schema, SchemaObject}, @@ -80,6 +82,13 @@ impl ThemeSettings { } } +pub fn observe_buffer_font_size_adjustment( + cx: &mut ViewContext, + f: impl 'static + Fn(&mut V, &mut ViewContext), +) -> Subscription { + cx.observe_global::(f) +} + pub fn adjusted_font_size(size: Pixels, cx: &mut AppContext) -> Pixels { if let Some(AdjustedBufferFontSize(adjusted_size)) = cx.try_global::() { let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size; From 8f1633e7980495ffaa52bd606c118a64031071cb Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 15 Jan 2024 16:49:06 -0800 Subject: [PATCH 2/4] Iterate from leaf to root when marking views dirty in notify --- crates/gpui/src/window.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 2a88a4f397..869d6b1826 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -2761,6 +2761,8 @@ impl<'a, V: 'static> ViewContext<'a, V> { .rendered_frame .dispatch_tree .view_path(self.view.entity_id()) + .into_iter() + .rev() { if !self.window.dirty_views.insert(view_id) { break; From 1e755aa00f73b3d7897a1c4e6f4030ac31db0006 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 15 Jan 2024 17:02:20 -0800 Subject: [PATCH 3/4] Notify global observers when removing a global --- crates/gpui/src/app.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 17f92efb58..41519f0ae4 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -843,6 +843,7 @@ impl AppContext { /// Remove the global of the given type from the app context. Does not notify global observers. pub fn remove_global(&mut self) -> G { let global_type = TypeId::of::(); + self.push_effect(Effect::NotifyGlobalObservers { global_type }); *self .globals_by_type .remove(&global_type) From d84785f7e8519b30e474385e5a72f5726cf4783e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 15 Jan 2024 17:03:02 -0800 Subject: [PATCH 4/4] Put back logic for resetting buffer font adjustment on settings change. --- crates/theme/src/theme.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index f8d90b7bdc..3b158ab9bb 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -20,7 +20,7 @@ mod user_theme; use std::sync::Arc; -use ::settings::Settings; +use ::settings::{Settings, SettingsStore}; pub use default_colors::*; pub use default_theme::*; pub use registry::*; @@ -62,13 +62,22 @@ pub enum LoadThemes { pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) { cx.set_global(ThemeRegistry::default()); + ThemeSettings::register(cx); + + let mut prev_buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size; + cx.observe_global::(move |cx| { + let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size; + if buffer_font_size != prev_buffer_font_size { + prev_buffer_font_size = buffer_font_size; + reset_font_size(cx); + } + }) + .detach(); match themes_to_load { LoadThemes::JustBase => (), LoadThemes::All => cx.global_mut::().load_user_themes(), } - - ThemeSettings::register(cx); } pub trait ActiveTheme {