Repository: lapce/lapce
File: lapce-data/src/config.rs (Rust)

Code before:

    pub fn get_color(&self, name: &str) -> Option<&Color> {
        self.themes.color(name)
    }

    /// Retrieve a color value whose key starts with "style."
    pub fn get_style_color(&self, name: &str) -> Option<&Color> {
        self.themes.style_color(name)
    }

    pub fn char_width(&self, text: &mut PietText, font_size: f64) -> f64 {
        let text_layout = text
            .new_text_layout("W")
            .font(self.editor.font_family(), font_size)
            .build()
            .unwrap();
        text_layout.size().width
    }

    pub fn editor_text_width(&self, text: &mut PietText, c: &str) -> f64 {
        let text_layout = text
            .new_text_layout(c.to_string())
            .font(self.editor.font_family(), self.editor.font_size as f64)
            .build()
            .unwrap();
        text_layout.size().width
    }

    pub fn editor_text_size(&self, text: &mut PietText, c: &str) -> Size {
        let text_layout = text
            .new_text_layout(c.to_string())
            .font(self.editor.font_family(), self.editor.font_size as f64)
            .build()
            .unwrap();
        text_layout.size()
    }

    pub fn update_recent_workspaces(workspaces: Vec<LapceWorkspace>) -> Option<()> {
        let path = Self::recent_workspaces_file()?;
        let mut array = toml::value::Array::new();
        for workspace in workspaces {
            if let Some(path) = workspace.path.as_ref() {
                let mut table = toml::value::Table::new();
                table.insert(
                    "kind".to_string(),
                    toml::Value::String(match workspace.kind {
                        LapceWorkspaceType::Local => "local".to_string(),
                        LapceWorkspaceType::RemoteSSH(user, host) => {
                            format!("ssh://{}@{}", user, host)
                        }
                        LapceWorkspaceType::RemoteWSL => "wsl".to_string(),

Review comment (suggestion):
Subjective: This call really is `char_width(text, self.editor.font_size as f64)`, or `editor_text_width`.

Code after:

    pub fn get_color(&self, name: &str) -> Option<&Color> {
        self.themes.color(name)
    }

    /// Retrieve a color value whose key starts with "style."
    pub fn get_style_color(&self, name: &str) -> Option<&Color> {
        self.themes.style_color(name)
    }

    /// Calculate the width of the character "W" (being the widest character)
    /// in the editor's current font family at the specified font size.
    pub fn char_width(&self, text: &mut PietText, font_size: f64) -> f64 {
        Self::editor_text_size_internal(
            self.editor.font_family(),
            font_size,
            text,
            "W",
        )
        .width
    }

    /// Calculate the width of the character "W" (being the widest character)
    /// in the editor's current font family and current font size.
    pub fn editor_char_width(&self, text: &mut PietText) -> f64 {
        Self::editor_text_size_internal(
            self.editor.font_family(),
            self.editor.font_size as f64,
            text,
            "W",
        )
        .width
    }

    /// Calculate the width of `text_to_measure` in the editor's current font family and font size.
    pub fn editor_text_width(
        &self,
        text: &mut PietText,
        text_to_measure: &str,
    ) -> f64 {
        Self::editor_text_size_internal(
            self.editor.font_family(),
            self.editor.font_size as f64,
            text,
            text_to_measure,
        )
        .width
    }

    /// Calculate the size of `text_to_measure` in the editor's current font family and font size.
    pub fn editor_text_size(