From 963120402829393f009247773dfe6fb6f8304fb8 Mon Sep 17 00:00:00 2001 From: Nacho114 <17376073+Nacho114@users.noreply.github.com> Date: Fri, 28 Jul 2023 17:24:31 +0200 Subject: [PATCH] feat(plugins): utility functions to find active pane and tab (#2652) --- zellij-tile/src/shim.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index bba14689..c12a6152 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -372,6 +372,31 @@ pub fn rename_tab>(tab_position: i32, new_name: S) { unsafe { host_rename_tab() }; } +// Utility Functions + +/// Returns the `TabInfo` corresponding to the currently active tab +fn get_focused_tab(tab_infos: &Vec) -> Option { + for tab_info in tab_infos { + if tab_info.active { + return Some(tab_info.clone()); + } + } + return None; +} + +/// Returns the `PaneInfo` corresponding to the currently active pane (ignoring plugins) +fn get_focused_pane(tab_position: usize, pane_manifest: &PaneManifest) -> Option { + let panes = pane_manifest.panes.get(&tab_position); + if let Some(panes) = panes { + for pane in panes { + if pane.is_focused & !pane.is_plugin { + return Some(pane.clone()); + } + } + } + None +} + // Internal Functions #[doc(hidden)]