Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Enable buffer font size adjustment in zed2
Max Brunsfeld89c8a7c2426a
diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rsindex 94ae8abc71a..8f9d22e6c9e 100644--- a/crates/editor2/src/editor.rs+++ b/crates/editor2/src/editor.rs@@ -9291,7 +9291,7 @@ impl Render for Editor {color: cx.theme().colors().text,font_family: settings.buffer_font.family.clone(),font_features: settings.buffer_font.features,- font_size: settings.buffer_font_size.into(),+ font_size: settings.buffer_font_size(cx).into(),font_weight: FontWeight::NORMAL,font_style: FontStyle::Normal,line_height: relative(settings.buffer_line_height.value()),diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rsindex 0715ace9eaf..9293302938c 100644--- a/crates/gpui2/src/app.rs+++ b/crates/gpui2/src/app.rs@@ -860,7 +860,6 @@ impl AppContext {}/// Remove the global of the given type from the app context. Does not notify global observers.- #[cfg(any(test, feature = "test-support"))]pub fn remove_global<G: Any>(&mut self) -> G {let global_type = TypeId::of::<G>();*selfdiff --git a/crates/theme2/src/settings.rs b/crates/theme2/src/settings.rsindex 15b578d4b0e..624b14fe33f 100644--- a/crates/theme2/src/settings.rs+++ b/crates/theme2/src/settings.rs@@ -27,7 +27,7 @@ pub struct ThemeSettings {}#[derive(Default)]-pub struct AdjustedBufferFontSize(Option<Pixels>);+pub struct AdjustedBufferFontSize(Pixels);#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]pub struct ThemeSettingsContent {@@ -69,12 +69,10 @@ impl BufferLineHeight {}impl ThemeSettings {- pub fn buffer_font_size(&self, cx: &mut AppContext) -> Pixels {- let font_size = *cx- .default_global::<AdjustedBufferFontSize>()- .0- .get_or_insert(self.buffer_font_size.into());- font_size.max(MIN_FONT_SIZE)+ pub fn buffer_font_size(&self, cx: &AppContext) -> Pixels {+ cx.try_global::<AdjustedBufferFontSize>()+ .map_or(self.buffer_font_size, |size| size.0)+ .max(MIN_FONT_SIZE)}pub fn line_height(&self) -> f32 {@@ -83,9 +81,9 @@ impl ThemeSettings {}pub fn adjusted_font_size(size: Pixels, cx: &mut AppContext) -> Pixels {- if let Some(adjusted_size) = cx.default_global::<AdjustedBufferFontSize>().0 {+ if let Some(AdjustedBufferFontSize(adjusted_size)) = cx.try_global::<AdjustedBufferFontSize>() {let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;- let delta = adjusted_size - buffer_font_size;+ let delta = *adjusted_size - buffer_font_size;size + delta} else {size@@ -95,18 +93,19 @@ pub fn adjusted_font_size(size: Pixels, cx: &mut AppContext) -> Pixels {pub fn adjust_font_size(cx: &mut AppContext, f: fn(&mut Pixels)) {let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;- let adjusted_size = cx- .default_global::<AdjustedBufferFontSize>()- .0- .get_or_insert(buffer_font_size);- f(adjusted_size);- *adjusted_size = (*adjusted_size).max(MIN_FONT_SIZE - buffer_font_size);+ let mut adjusted_size = cx+ .try_global::<AdjustedBufferFontSize>()+ .map_or(buffer_font_size, |adjusted_size| adjusted_size.0);++ f(&mut adjusted_size);+ adjusted_size = adjusted_size.max(MIN_FONT_SIZE);+ cx.set_global(AdjustedBufferFontSize(adjusted_size));cx.refresh();}pub fn reset_font_size(cx: &mut AppContext) {if cx.has_global::<AdjustedBufferFontSize>() {- cx.global_mut::<AdjustedBufferFontSize>().0 = None;+ cx.remove_global::<AdjustedBufferFontSize>();cx.refresh();}}diff --git a/crates/ui2/src/styled_ext.rs b/crates/ui2/src/styled_ext.rsindex e567830d6ca..0f882b49634 100644--- a/crates/ui2/src/styled_ext.rs+++ b/crates/ui2/src/styled_ext.rs@@ -70,8 +70,7 @@ pub trait StyledExt: Styled + Sized {/// or other places that text needs to match the user's buffer font size.fn text_buffer(self, cx: &mut WindowContext) -> Self {let settings = ThemeSettings::get_global(cx);-- self.text_size(settings.buffer_font_size)+ self.text_size(settings.buffer_font_size(cx))}/// The [`Surface`](ui2::ElevationIndex::Surface) elevation level, located above the app background, is the standard level for all elementsdiff --git a/crates/zed2/src/zed2.rs b/crates/zed2/src/zed2.rsindex d220250b3db..45ace75ebcc 100644--- a/crates/zed2/src/zed2.rs+++ b/crates/zed2/src/zed2.rs@@ -235,14 +235,13 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {.open_urls(&[action.url.clone()])}).register_action(|_, action: &OpenBrowser, cx| cx.open_url(&action.url))- //todo!(buffer font size)- // cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {- // theme::adjust_font_size(cx, |size| *size += 1.0)- // });- // cx.add_global_action(move |_: &DecreaseBufferFontSize, cx| {- // theme::adjust_font_size(cx, |size| *size -= 1.0)- // });- // cx.add_global_action(move |_: &ResetBufferFontSize, cx| theme::reset_font_size(cx));+ .register_action(move |_, _: &IncreaseBufferFontSize, cx| {+ theme::adjust_font_size(cx, |size| *size += px(1.0))+ })+ .register_action(move |_, _: &DecreaseBufferFontSize, cx| {+ theme::adjust_font_size(cx, |size| *size -= px(1.0))+ })+ .register_action(move |_, _: &ResetBufferFontSize, cx| theme::reset_font_size(cx)).register_action(|_, _: &install_cli::Install, cx| {cx.spawn(|_, cx| async move {install_cli::install_cli(cx.deref())