settings: Use a derive macro for refine (#38451)
When we refactored settings to not pass JSON blobs around, we ended up needing to write *a lot* of code that just merged things (like json merge used to do). Use a derive macro to prevent typos in this logic. Release Notes: - N/A
This commit is contained in:
+1
-27
@@ -45,7 +45,6 @@ use std::{mem, ops::Range, sync::Arc};
|
||||
use surrounds::SurroundsType;
|
||||
use theme::ThemeSettings;
|
||||
use ui::{IntoElement, SharedString, px};
|
||||
use util::MergeFrom;
|
||||
use vim_mode_setting::HelixModeSetting;
|
||||
use vim_mode_setting::VimModeSetting;
|
||||
use workspace::{self, Pane, Workspace};
|
||||
@@ -1845,7 +1844,7 @@ impl From<settings::ModeContent> for Mode {
|
||||
}
|
||||
|
||||
impl Settings for VimSettings {
|
||||
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
let vim = content.vim.clone().unwrap();
|
||||
Self {
|
||||
default_mode: vim.default_mode.unwrap().into(),
|
||||
@@ -1857,29 +1856,4 @@ impl Settings for VimSettings {
|
||||
cursor_shape: vim.cursor_shape.unwrap().into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
|
||||
let Some(vim) = content.vim.as_ref() else {
|
||||
return;
|
||||
};
|
||||
self.default_mode
|
||||
.merge_from(&vim.default_mode.map(Into::into));
|
||||
self.toggle_relative_line_numbers
|
||||
.merge_from(&vim.toggle_relative_line_numbers);
|
||||
self.use_system_clipboard
|
||||
.merge_from(&vim.use_system_clipboard);
|
||||
self.use_smartcase_find.merge_from(&vim.use_smartcase_find);
|
||||
self.custom_digraphs.merge_from(&vim.custom_digraphs);
|
||||
self.highlight_on_yank_duration
|
||||
.merge_from(&vim.highlight_on_yank_duration);
|
||||
self.cursor_shape
|
||||
.merge_from(&vim.cursor_shape.map(Into::into));
|
||||
}
|
||||
|
||||
fn import_from_vscode(
|
||||
_vscode: &settings::VsCodeSettings,
|
||||
_current: &mut settings::SettingsContent,
|
||||
) {
|
||||
// TODO: translate vim extension settings
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user