Repository: lapce/lapce
File: lapce-ui/src/settings.rs (Rust)

Code before:
                (
                    "ui".to_string(),
                    UIConfig::FIELDS.to_vec(),
                    UIConfig::DESCS.to_vec(),
                    settings,
                )
            }
            LapceSettingsKind::Editor => {
                let settings: HashMap<String, serde_json::Value> =
                    serde_json::from_value(
                        serde_json::to_value(&data.config.editor).unwrap(),
                    )
                    .unwrap();
                (
                    "editor".to_string(),
                    EditorConfig::FIELDS.to_vec(),
                    EditorConfig::DESCS.to_vec(),
                    settings,
                )
            }
            LapceSettingsKind::Terminal => {
                let settings: HashMap<String, serde_json::Value> =
                    serde_json::from_value(
                        serde_json::to_value(&data.config.terminal).unwrap(),
                    )
                    .unwrap();
                (
                    "terminal".to_string(),
                    TerminalConfig::FIELDS.to_vec(),
                    TerminalConfig::DESCS.to_vec(),
                    settings,
                )
            }
        };

        for (i, field) in fields.into_iter().enumerate() {
            let field = field.replace('_', "-");
            self.children.push(WidgetPod::new(
                LapcePadding::new(
                    (10.0, 10.0),
                    LapceSettingsItem::new(
                        data,
                        kind.clone(),
                        field.clone(),
                        descs[i].to_string(),
                        settings.get(&field).unwrap().clone(),
                        ctx.get_external_handle(),
                    ),
                )
                .boxed(),
            ))

Review comment (suggestion):
Ideally, all of these strings should be turned into `&'static str` but I did not want to limit flexibility. They might turn into `ReadOnlyString`s, though.

Code after:
                into_settings_map(&data.config.ui),
            ),
            LapceSettingsKind::Editor => (
                "editor",
                &EditorConfig::FIELDS[..],
                &EditorConfig::DESCS[..],
                into_settings_map(&data.config.editor),
            ),
            LapceSettingsKind::Terminal => (
                "terminal",
                &TerminalConfig::FIELDS[..],
                &TerminalConfig::DESCS[..],
                into_settings_map(&data.config.terminal),
            ),
        };

        for (field, desc) in fields.iter().zip(descs.iter()) {
            // TODO(dbuga): we should generate kebab-case field names
            let field = field.replace('_', "-");
            let value = settings.remove(&field).unwrap();
            self.children.push(WidgetPod::new(
                LapcePadding::new(
                    (10.0, 10.0),
                    LapceSettingsItem::new(
                        data,
                        kind.to_string(),
                        field,
                        desc.to_string(),
                        value,
                        ctx.get_external_handle(),
                    ),
                )
                .boxed(),
            ))
        }
    }
}

impl Widget<LapceTabData> for LapceSettings {
    fn id(&self) -> Option<WidgetId> {
        Some(self.widget_id)
    }

    fn event(
        &mut self,
        ctx: &mut EventCtx,
        event: &Event,
        data: &mut LapceTabData,
        env: &Env,
    ) {
        for child in self.children.iter_mut() {