diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-06 00:41:19 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-06 00:41:19 +0300 |
| commit | b7619db085eb4054a071b51159eda65d6b60f3fe (patch) | |
| tree | 19e6885b47b67dcad5beefa1ca487de170085dcd /src/app/actions.rs | |
| parent | 556b16b2df7ea2c3e9b8ad13db4ad7370c1ad838 (diff) | |
feat: expose pane zoom api
Diffstat (limited to 'src/app/actions.rs')
| -rw-r--r-- | src/app/actions.rs | 97 |
1 files changed, 87 insertions, 10 deletions
diff --git a/src/app/actions.rs b/src/app/actions.rs index 8124be93..17daa6ff 100644 --- a/src/app/actions.rs +++ b/src/app/actions.rs @@ -1350,6 +1350,28 @@ impl AppState { // Pane operations // --------------------------------------------------------------------------- +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) enum PaneZoomCommand { + Toggle, + On, + Off, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) enum PaneZoomNoopReason { + SinglePane, + AlreadyZoomed, + AlreadyUnzoomed, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) struct PaneZoomOutcome { + pub changed: bool, + pub focus_changed: bool, + pub reason: Option<PaneZoomNoopReason>, + pub zoomed: bool, +} + impl AppState { pub fn navigate_pane(&mut self, direction: NavDirection) { let Some(ws_idx) = self.active else { @@ -1468,17 +1490,72 @@ impl AppState { } } - pub fn toggle_zoom(&mut self) { - if let Some(tab) = self - .active - .and_then(|i| self.workspaces.get_mut(i)) - .and_then(|ws| ws.active_tab_mut()) - { - if tab.layout.pane_count() > 1 { - tab.zoomed = !tab.zoomed; - self.mark_session_dirty(); - } + pub(crate) fn apply_pane_zoom( + &mut self, + ws_idx: usize, + pane_id: PaneId, + command: PaneZoomCommand, + ) -> Option<PaneZoomOutcome> { + let tab_idx = self + .workspaces + .get(ws_idx)? + .find_tab_index_for_pane(pane_id)?; + let focus_changed = self.focus_pane_in_workspace(ws_idx, pane_id); + let tab = self + .workspaces + .get_mut(ws_idx) + .and_then(|ws| ws.tabs.get_mut(tab_idx))?; + if tab.layout.pane_count() <= 1 { + return Some(PaneZoomOutcome { + changed: false, + focus_changed, + reason: Some(PaneZoomNoopReason::SinglePane), + zoomed: tab.zoomed, + }); } + + let desired = match command { + PaneZoomCommand::Toggle => !tab.zoomed, + PaneZoomCommand::On => true, + PaneZoomCommand::Off => false, + }; + let reason = match (command, tab.zoomed) { + (PaneZoomCommand::On, true) => Some(PaneZoomNoopReason::AlreadyZoomed), + (PaneZoomCommand::Off, false) => Some(PaneZoomNoopReason::AlreadyUnzoomed), + _ => None, + }; + if reason.is_some() { + return Some(PaneZoomOutcome { + changed: false, + focus_changed, + reason, + zoomed: tab.zoomed, + }); + } + + tab.zoomed = desired; + let zoomed = tab.zoomed; + self.mark_session_dirty(); + Some(PaneZoomOutcome { + changed: true, + focus_changed, + reason: None, + zoomed, + }) + } + + pub fn toggle_zoom(&mut self) { + let Some(ws_idx) = self.active else { + return; + }; + let Some(pane_id) = self + .workspaces + .get(ws_idx) + .and_then(crate::workspace::Workspace::focused_pane_id) + else { + return; + }; + self.apply_pane_zoom(ws_idx, pane_id, PaneZoomCommand::Toggle); } pub(crate) fn workspace_close_would_close_worktree_group(&self, ws_idx: usize) -> bool { |
