diff --git a/src/main.rs b/src/main.rs index 4a0058d..b659cd6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -397,7 +397,6 @@ pub struct App { curr_font_weights: Vec, curr_font_stretch_names: Vec, curr_font_stretches: Vec, - zoom_adj: i8, zoom_step_names: Vec, zoom_steps: Vec, theme_names_dark: Vec, @@ -477,6 +476,18 @@ impl App { .sort_by(|a, b| LANGUAGE_SORTER.compare(a, b)); } + + fn reset_terminal_panes_zoom(&mut self) { + for (_pane, tab_model) in self.pane_model.panes.iter() { + for entity in tab_model.iter() { + if let Some(terminal) = tab_model.data::>(entity) { + let mut terminal = terminal.lock().unwrap(); + terminal.set_zoom_adj(0); + } + } + } + } + fn update_config(&mut self) -> Command { let theme = self.config.app_theme.theme(); @@ -499,7 +510,7 @@ impl App { for entity in tab_model.iter() { if let Some(terminal) = tab_model.data::>(entity) { let mut terminal = terminal.lock().unwrap(); - terminal.set_config(&self.config, &self.themes, self.zoom_adj); + terminal.set_config(&self.config, &self.themes); } } } @@ -511,6 +522,29 @@ impl App { cosmic::app::command::set_theme(theme) } + fn update_render_active_pane_zoom(&mut self, zoom_message: Message) -> Command { + // skip writing config to fs when zoom in/ out + // recalculate the pane due to the changes of zoom_adj value + // but only for the active pane/tab + if let Some(tab_model) = self.pane_model.active() { + for entity in tab_model.iter() { + if tab_model.is_active(entity) { + if let Some(terminal) = tab_model.data::>(entity) { + let mut terminal = terminal.lock().unwrap(); + let current_zoom_adj = terminal.zoom_adj(); + match zoom_message { + Message::ZoomIn => terminal.set_zoom_adj(current_zoom_adj.saturating_add(1)), + Message::ZoomOut => terminal.set_zoom_adj(current_zoom_adj.saturating_sub(1)), + _ => {} + } + terminal.set_config(&self.config, &self.themes); + } + } + } + } + Command::none() + } + fn save_color_schemes(&mut self, color_scheme_kind: ColorSchemeKind) -> Command { // Optimized for just saving color_schemes if let Some(ref config_handler) = self.config_handler { @@ -1253,7 +1287,7 @@ impl App { tab_title_override, ) { Ok(mut terminal) => { - terminal.set_config(&self.config, &self.themes, self.zoom_adj); + terminal.set_config(&self.config, &self.themes); tab_model .data_set::>(entity, Mutex::new(terminal)); } @@ -1451,7 +1485,6 @@ impl Application for App { curr_font_weights: Vec::new(), curr_font_stretch_names: Vec::new(), curr_font_stretches: Vec::new(), - zoom_adj: 0, zoom_step_names, zoom_steps, theme_names_dark: Vec::new(), @@ -1528,7 +1561,6 @@ impl Application for App { } }; } - match message { Message::AppTheme(app_theme) => { config_set!(app_theme, app_theme); @@ -1831,7 +1863,7 @@ impl Application for App { Message::DefaultFontSize(index) => match self.font_sizes.get(index) { Some(font_size) => { config_set!(font_size, *font_size); - self.zoom_adj = 0; // reset zoom + self.reset_terminal_panes_zoom(); // reset zoom return self.update_config(); } None => { @@ -1878,7 +1910,7 @@ impl Application for App { Message::DefaultZoomStep(index) => match self.zoom_steps.get(index) { Some(zoom_step) => { config_set!(font_size_zoom_step_mul_100, *zoom_step); - self.zoom_adj = 0; // reset zoom + self.reset_terminal_panes_zoom(); // reset zoom return self.update_config(); } None => { @@ -2514,15 +2546,13 @@ impl Application for App { } }, Message::ZoomIn => { - self.zoom_adj = self.zoom_adj.saturating_add(1); - return self.update_config(); + return self.update_render_active_pane_zoom(message); } Message::ZoomOut => { - self.zoom_adj = self.zoom_adj.saturating_sub(1); - return self.update_config(); + return self.update_render_active_pane_zoom(message); } Message::ZoomReset => { - self.zoom_adj = 0; + self.reset_terminal_panes_zoom(); return self.update_config(); } } diff --git a/src/terminal.rs b/src/terminal.rs index 2ce5dc2..0234073 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -139,6 +139,7 @@ fn convert_color(colors: &Colors, color: Color) -> cosmic_text::Color { } type TabModel = segmented_button::Model; + pub struct TerminalPaneGrid { pub panes: pane_grid::State, pub panes_created: usize, @@ -212,6 +213,7 @@ pub struct Terminal { search_value: String, size: Size, use_bright_bold: bool, + zoom_adj: i8 } impl Terminal { @@ -303,6 +305,7 @@ impl Terminal { tab_title_override, term, use_bright_bold, + zoom_adj: Default::default() }) } @@ -332,6 +335,14 @@ impl Terminal { self.size } + pub fn zoom_adj(&self) -> i8 { + self.zoom_adj + } + + pub fn set_zoom_adj(&mut self, value: i8) { + self.zoom_adj = value; + } + pub fn redraw(&self) -> bool { self.buffer.redraw() } @@ -528,11 +539,10 @@ impl Terminal { &mut self, config: &AppConfig, themes: &HashMap<(String, ColorSchemeKind), Colors>, - zoom_adj: i8, ) { let mut update_cell_size = false; let mut update = false; - + let zoom_adj = self.zoom_adj; if self.default_attrs.stretch != config.typed_font_stretch() { self.default_attrs = self.default_attrs.stretch(config.typed_font_stretch()); update_cell_size = true;