diff --git a/src/app/config.rs b/src/app/config.rs index 7f14af5..246135a 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -21,6 +21,8 @@ pub struct Config { pub font_family: String, #[serde(default = "default_font_size")] pub font_size: f32, + #[serde(default = "default_syntax_highlighting")] + pub syntax_highlighting: bool, // pub vim_mode: bool, } @@ -45,18 +47,22 @@ fn default_font_family() -> String { fn default_font_size() -> f32 { 14.0 } +fn default_syntax_highlighting() -> bool { + false +} impl Default for Config { fn default() -> Self { Self { - auto_hide_toolbar: false, - hide_tab_bar: true, - show_line_numbers: false, - word_wrap: true, + auto_hide_toolbar: default_auto_hide_toolbar(), + hide_tab_bar: default_hide_tab_bar(), + show_line_numbers: default_show_line_numbers(), + word_wrap: default_word_wrap(), theme: Theme::default(), - line_side: false, - font_family: "Proportional".to_string(), - font_size: 14.0, + line_side: default_line_side(), + font_family: default_font_family(), + font_size: default_font_size(), + syntax_highlighting: default_syntax_highlighting(), // vim_mode: false, } } @@ -65,11 +71,9 @@ impl Default for Config { impl Config { pub fn config_path() -> Option { let config_dir = if let Some(config_dir) = dirs::config_dir() { - config_dir.join(format!("{}", env!("CARGO_PKG_NAME"))) + config_dir.join(env!("CARGO_PKG_NAME")) } else if let Some(home_dir) = dirs::home_dir() { - home_dir - .join(".config") - .join(format!("{}", env!("CARGO_PKG_NAME"))) + home_dir.join(".config").join(env!("CARGO_PKG_NAME")) } else { return None; }; diff --git a/src/app/state/config.rs b/src/app/state/config.rs index 5e00e5f..9ec8d20 100644 --- a/src/app/state/config.rs +++ b/src/app/state/config.rs @@ -1,21 +1,10 @@ use super::editor::TextEditor; use crate::app::config::Config; -use crate::app::tab::Tab; use crate::app::theme; impl TextEditor { pub fn from_config(config: Config) -> Self { Self { - tabs: vec![Tab::new_empty(1)], - active_tab_index: 0, - tab_counter: 1, - show_about: false, - show_shortcuts: false, - show_find: false, - show_preferences: false, - pending_unsaved_action: None, - force_quit_confirmed: false, - clean_quit_requested: false, show_line_numbers: config.show_line_numbers, word_wrap: config.word_wrap, auto_hide_toolbar: config.auto_hide_toolbar, @@ -24,30 +13,8 @@ impl TextEditor { line_side: config.line_side, font_family: config.font_family, font_size: config.font_size, - font_size_input: None, - zoom_factor: 1.0, - menu_interaction_active: false, - tab_bar_rect: None, - menu_bar_stable_until: None, - text_processing_result: std::sync::Arc::new(std::sync::Mutex::new(Default::default())), - _processing_thread_handle: None, - find_query: String::new(), - replace_query: String::new(), - find_matches: Vec::new(), - current_match_index: None, - case_sensitive_search: false, - show_replace_section: false, - prev_show_find: false, - focus_find: false, - // vim_mode: config.vim_mode, - previous_cursor_position: None, - previous_content: String::new(), - previous_cursor_char_index: None, - current_cursor_line: 0, - previous_cursor_line: 0, - font_settings_changed: false, - text_needs_processing: false, - should_select_current_match: false, + syntax_highlighting: config.syntax_highlighting, + ..Default::default() } } @@ -87,6 +54,7 @@ impl TextEditor { line_side: self.line_side, font_family: self.font_family.to_string(), font_size: self.font_size, + syntax_highlighting: self.syntax_highlighting, // vim_mode: self.vim_mode, } } diff --git a/src/app/state/default.rs b/src/app/state/default.rs index 63960fa..9e0a6d5 100644 --- a/src/app/state/default.rs +++ b/src/app/state/default.rs @@ -20,6 +20,7 @@ impl Default for TextEditor { word_wrap: true, auto_hide_toolbar: false, hide_tab_bar: true, + syntax_highlighting: false, theme: Theme::default(), line_side: false, font_family: "Proportional".to_string(), diff --git a/src/app/state/editor.rs b/src/app/state/editor.rs index ca330f0..2f00370 100644 --- a/src/app/state/editor.rs +++ b/src/app/state/editor.rs @@ -45,6 +45,7 @@ pub struct TextEditor { pub(crate) word_wrap: bool, pub(crate) auto_hide_toolbar: bool, pub(crate) hide_tab_bar: bool, + pub(crate) syntax_highlighting: bool, pub(crate) theme: Theme, pub(crate) line_side: bool, pub(crate) font_family: String,