ced/src/app/state/config.rs

100 lines
3.4 KiB
Rust
Raw Normal View History

2025-07-05 14:42:45 -04:00
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,
2025-07-15 00:42:01 -04:00
auto_hide_tab_bar: config.auto_hide_tab_bar,
2025-07-05 14:42:45 -04:00
theme: config.theme,
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,
2025-07-05 14:42:45 -04:00
find_query: String::new(),
find_matches: Vec::new(),
current_match_index: None,
case_sensitive_search: false,
prev_show_find: false,
// vim_mode: config.vim_mode,
2025-07-15 00:42:01 -04:00
2025-07-05 14:42:45 -04:00
// Cursor tracking for smart scrolling
previous_cursor_position: None,
2025-07-15 00:42:01 -04:00
// Track previous content for incremental processing
previous_content: String::new(),
previous_cursor_char_index: None,
current_cursor_line: 0,
previous_cursor_line: 0,
2025-07-15 09:53:45 -04:00
font_settings_changed: false,
2025-07-05 14:42:45 -04:00
}
}
pub fn from_config_with_context(config: Config, cc: &eframe::CreationContext<'_>) -> Self {
let mut editor = Self::from_config(config);
theme::apply(editor.theme, &cc.egui_ctx);
cc.egui_ctx.options_mut(|o| o.zoom_with_keyboard = false);
let mut style = (*cc.egui_ctx.style()).clone();
style
.text_styles
.insert(egui::TextStyle::Body, egui::FontId::proportional(16.0));
style
.text_styles
.insert(egui::TextStyle::Button, egui::FontId::proportional(16.0));
style
.text_styles
.insert(egui::TextStyle::Heading, egui::FontId::proportional(22.0));
style
.text_styles
.insert(egui::TextStyle::Small, egui::FontId::proportional(14.0));
cc.egui_ctx.set_style(style);
editor.apply_font_settings(&cc.egui_ctx);
editor
}
pub fn get_config(&self) -> Config {
Config {
auto_hide_toolbar: self.auto_hide_toolbar,
show_line_numbers: self.show_line_numbers,
2025-07-15 00:42:01 -04:00
auto_hide_tab_bar: self.auto_hide_tab_bar,
2025-07-05 14:42:45 -04:00
word_wrap: self.word_wrap,
theme: self.theme,
line_side: self.line_side,
font_family: self.font_family.clone(),
font_size: self.font_size,
// vim_mode: self.vim_mode,
}
}
pub fn save_config(&self) {
let config = self.get_config();
if let Err(e) = config.save() {
2025-07-15 00:42:01 -04:00
eprintln!("Failed to save configuration: {e}");
2025-07-05 14:42:45 -04:00
}
}
}