settings_ui: Fix IEEE 754 floating point error when serializing value to JSON (#40677)
Closes #40556 Release Notes: - settings-ui: Fixed an issue where modifying floating point number fields could result in the values written to the settings file containing IEEE 754 floating point error > [!Note] > Seems like there's another pull request fixing the centered layout in #40661 by normalizing the whole `settings.json` file when updating it. Not sure which is the better way to handle this issue. ## Description This pull request solves the IEEE 754 floating point error when serializing values from settings-ui into `settings.json` by creating a two `serde_helper` to convert the problematic f32 into a formatted two decimal placed f32. Fields currently exists the IEEE 754 error: - Appearance → Unnecessary Code Fade - Editor → Drop Size Target - Window & Layout → Centered Layout Left/Right Padding - Window & Layout → Inactive Opacity ## How to verify ### Unnecessary Code Fade As Is | To Be --- | --- <video src="https://github.com/user-attachments/assets/1bf4bad2-63c5-4b03-ac29-8b6b59569e16" /> | <video src="https://github.com/user-attachments/assets/dadcd4a1-651b-43dd-913f-edae073ceb68" /> ### Drop Size Target As Is | To Be --- | --- <video src="https://github.com/user-attachments/assets/9d5b4173-fcac-44d0-b7fc-772a2e426ef1" /> | <video src="https://github.com/user-attachments/assets/4b5adeaf-e678-494d-bd1b-6c1d55824c43" /> ### Centered Layout Left/Right Padding As Is | To Be --- | --- <video src="https://github.com/user-attachments/assets/33b4e1ff-7ab2-44f7-9e9b-8abad1565d9a" /> | <video src="https://github.com/user-attachments/assets/63d8de9e-28d1-4bd7-a6c9-02452e105486" /> ### Inactive Opacity As Is | To Be --- | --- <video src="https://github.com/user-attachments/assets/a7fe2e72-deb6-41dc-82f3-e2649503b8a4" /> | <video src="https://github.com/user-attachments/assets/993c314f-b6f6-4dcd-8f74-fa357ab063e9" /> --------- Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
@@ -9,6 +9,8 @@ use std::{fmt::Display, sync::Arc};
|
||||
|
||||
use serde_with::skip_serializing_none;
|
||||
|
||||
use crate::serialize_f32_with_two_decimal_places;
|
||||
|
||||
/// Settings for rendering text in UI and text buffers.
|
||||
|
||||
#[skip_serializing_none]
|
||||
@@ -16,6 +18,7 @@ use serde_with::skip_serializing_none;
|
||||
pub struct ThemeSettingsContent {
|
||||
/// The default font size for text in the UI.
|
||||
#[serde(default)]
|
||||
#[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
|
||||
pub ui_font_size: Option<f32>,
|
||||
/// The name of a font to use for rendering in the UI.
|
||||
#[serde(default)]
|
||||
@@ -42,6 +45,7 @@ pub struct ThemeSettingsContent {
|
||||
pub buffer_font_fallbacks: Option<Vec<FontFamilyName>>,
|
||||
/// The default font size for rendering in text buffers.
|
||||
#[serde(default)]
|
||||
#[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
|
||||
pub buffer_font_size: Option<f32>,
|
||||
/// The weight of the editor font in CSS units from 100 to 900.
|
||||
#[serde(default)]
|
||||
@@ -56,9 +60,11 @@ pub struct ThemeSettingsContent {
|
||||
pub buffer_font_features: Option<FontFeatures>,
|
||||
/// The font size for agent responses in the agent panel. Falls back to the UI font size if unset.
|
||||
#[serde(default)]
|
||||
#[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
|
||||
pub agent_ui_font_size: Option<f32>,
|
||||
/// The font size for user messages in the agent panel.
|
||||
#[serde(default)]
|
||||
#[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
|
||||
pub agent_buffer_font_size: Option<f32>,
|
||||
/// The name of the Zed theme to use.
|
||||
#[serde(default)]
|
||||
@@ -104,7 +110,7 @@ pub struct ThemeSettingsContent {
|
||||
derive_more::FromStr,
|
||||
)]
|
||||
#[serde(transparent)]
|
||||
pub struct CodeFade(pub f32);
|
||||
pub struct CodeFade(#[serde(serialize_with = "serialize_f32_with_two_decimal_places")] pub f32);
|
||||
|
||||
impl Display for CodeFade {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
|
||||
Reference in New Issue
Block a user