Clear buffer font size adjustments when buffer font size setting changes

This commit is contained in:
Max Brunsfeld 2023-05-17 16:14:05 -07:00
parent 823e15d85a
commit a56793c214
2 changed files with 16 additions and 3 deletions

View file

@ -10,6 +10,7 @@ use gpui::{
};
use serde::{de::DeserializeOwned, Deserialize};
use serde_json::Value;
use settings::SettingsStore;
use std::{collections::HashMap, sync::Arc};
use ui::{ButtonStyle, CheckboxStyle, IconStyle, ModalStyle, SvgStyle};
@ -23,6 +24,16 @@ pub fn current(cx: &AppContext) -> Arc<Theme> {
pub fn init(source: impl AssetSource, cx: &mut AppContext) {
cx.set_global(ThemeRegistry::new(source, cx.font_cache().clone()));
settings::register::<ThemeSettings>(cx);
let mut prev_buffer_font_size = settings::get::<ThemeSettings>(cx).buffer_font_size;
cx.observe_global::<SettingsStore, _>(move |cx| {
let buffer_font_size = settings::get::<ThemeSettings>(cx).buffer_font_size;
if buffer_font_size != prev_buffer_font_size {
prev_buffer_font_size = buffer_font_size;
reset_font_size(cx);
}
})
.detach();
}
#[derive(Deserialize, Default)]

View file

@ -19,7 +19,7 @@ pub struct ThemeSettings {
pub buffer_font_family_name: String,
pub buffer_font_features: fonts::Features,
pub buffer_font_family: FamilyId,
buffer_font_size: f32,
pub(crate) buffer_font_size: f32,
pub theme: Arc<Theme>,
}
@ -75,8 +75,10 @@ pub fn adjust_font_size(cx: &mut AppContext, f: fn(&mut f32)) {
}
pub fn reset_font_size(cx: &mut AppContext) {
cx.remove_global::<AdjustedBufferFontSize>();
cx.refresh_windows();
if cx.has_global::<AdjustedBufferFontSize>() {
cx.remove_global::<AdjustedBufferFontSize>();
cx.refresh_windows();
}
}
impl settings::Setting for ThemeSettings {