Continue improving font adjustment settings (#24908)

Follow-up of https://github.com/zed-industries/zed/pull/24857

Based on the feedback,

* made non-persisting font size change as a default in Zed keymaps
JetBrains IDEs seem to persist font size changes by default, hence left
to do so in Zed keymaps too

* fixed a bug with holding a binding to change the font size caused
flickering

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2025-02-14 23:00:56 +02:00 committed by GitHub
parent c049df2a2e
commit bd105a5fc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 38 deletions

View file

@ -557,9 +557,10 @@ impl BufferLineHeight {
impl ThemeSettings {
/// Returns the buffer font size.
pub fn buffer_font_size(&self, cx: &App) -> Pixels {
cx.try_global::<AdjustedBufferFontSize>()
.map_or(self.buffer_font_size, |size| size.0)
.max(MIN_FONT_SIZE)
let font_size = cx
.try_global::<AdjustedBufferFontSize>()
.map_or(self.buffer_font_size, |size| size.0);
clamp_font_size(font_size)
}
// TODO: Rename: `line_height` -> `buffer_line_height`
@ -644,14 +645,16 @@ pub fn observe_buffer_font_size_adjustment<V: 'static>(
/// Sets the adjusted buffer font size.
pub fn adjusted_font_size(size: Pixels, cx: &App) -> Pixels {
if let Some(AdjustedBufferFontSize(adjusted_size)) = cx.try_global::<AdjustedBufferFontSize>() {
let adjusted_font_size = 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;
size + delta
} else {
size
}
.max(MIN_FONT_SIZE)
};
clamp_font_size(adjusted_font_size)
}
/// Returns the adjusted buffer font size.
@ -669,8 +672,7 @@ pub fn adjust_buffer_font_size(cx: &mut App, mut f: impl FnMut(&mut Pixels)) {
.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.set_global(AdjustedBufferFontSize(clamp_font_size(adjusted_size)));
cx.refresh_windows();
}
@ -715,8 +717,7 @@ pub fn adjust_ui_font_size(cx: &mut App, mut f: impl FnMut(&mut Pixels)) {
.map_or(ui_font_size, |adjusted_size| adjusted_size.0);
f(&mut adjusted_size);
adjusted_size = adjusted_size.max(MIN_FONT_SIZE);
cx.set_global(AdjustedUiFontSize(adjusted_size));
cx.set_global(AdjustedUiFontSize(clamp_font_size(adjusted_size)));
cx.refresh_windows();
}
@ -733,6 +734,11 @@ pub fn reset_ui_font_size(cx: &mut App) {
}
}
/// Ensures font size is within the valid range.
pub fn clamp_font_size(size: Pixels) -> Pixels {
size.max(MIN_FONT_SIZE)
}
fn clamp_font_weight(weight: f32) -> FontWeight {
FontWeight(weight.clamp(100., 950.))
}