Limit the value can be set for font weight (#18594)
Some checks are pending
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run

Closes #18531



This PR limits the range of values that can be set for `FontWeight`.
Since any value less than 1.0 or greater than 999.9 causes Zed to crash
on Windows, I’ve restricted `FontWeight` to this range.

I could apply this constraint only on Windows, but considering the
documentation at https://zed.dev/docs/configuring-zed#buffer-font-weight
indicates that `FontWeight` should be between 100 and 900, I thought it
might be a good idea to apply this restriction in the settings.


Release Notes:

- Changed `ui_font_weight` and `buffer_font_weight` settings to require
values to be between `100` and `950` (inclusive).

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
Junkui Zhang 2024-10-02 01:32:31 +08:00 committed by GitHub
parent d14e36b323
commit 9b148f3dcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -520,6 +520,10 @@ pub fn reset_ui_font_size(cx: &mut AppContext) {
}
}
fn clamp_font_weight(weight: f32) -> FontWeight {
FontWeight(weight.clamp(100., 950.))
}
impl settings::Settings for ThemeSettings {
const KEY: Option<&'static str> = None;
@ -579,7 +583,7 @@ impl settings::Settings for ThemeSettings {
this.buffer_font.fallbacks = Some(FontFallbacks::from_fonts(value));
}
if let Some(value) = value.buffer_font_weight {
this.buffer_font.weight = FontWeight(value);
this.buffer_font.weight = clamp_font_weight(value);
}
if let Some(value) = value.ui_font_family.clone() {
@ -592,7 +596,7 @@ impl settings::Settings for ThemeSettings {
this.ui_font.fallbacks = Some(FontFallbacks::from_fonts(value));
}
if let Some(value) = value.ui_font_weight {
this.ui_font.weight = FontWeight(value);
this.ui_font.weight = clamp_font_weight(value);
}
if let Some(value) = &value.theme {