diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-04-03 18:04:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 18:04:06 +0200 |
commit | 3a428effed2327b8f82bd8cd328f385032e5bc06 (patch) | |
tree | b100fa9b9bb49583e8efee7567973ded1e8b87ae | |
parent | 63d6711a8dad531b3188b32fa19642c76cb7eec6 (diff) |
feat(panes): allow defining an expanded stacked pane (#2343)
* feat(panes): allow defining an expanded stacked pane
* style(fmt): rustfmt
56 files changed, 649 insertions, 56 deletions
diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs index 89a329bb4..4cc7279d7 100644 --- a/zellij-server/src/panes/tiled_panes/mod.rs +++ b/zellij-server/src/panes/tiled_panes/mod.rs @@ -423,7 +423,7 @@ impl TiledPanes { .unwrap_or(false) { let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) - .focus_pane(&pane_id); + .expand_pane(&pane_id); } self.active_panes .insert(client_id, pane_id, &mut self.panes); @@ -446,7 +446,7 @@ impl TiledPanes { { let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) - .focus_pane(&pane_id); + .expand_pane(&pane_id); } self.active_panes .insert(client_id, *pane_id, &mut self.panes); @@ -465,7 +465,7 @@ impl TiledPanes { &mut self.panes, &self.panes_to_hide, ) - .focus_pane(&pane_id); + .expand_pane(&pane_id); } self.active_panes .insert(client_id, pane_id, &mut self.panes); @@ -477,6 +477,33 @@ impl TiledPanes { self.set_force_render(); self.reapply_pane_frames(); } + pub fn expand_pane_in_stack(&mut self, pane_id: PaneId) -> Vec<PaneId> { + // returns all pane ids in stack + match StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) + .expand_pane(&pane_id) + { + Ok(all_panes_in_stack) => { + let connected_clients: Vec<ClientId> = + self.connected_clients.borrow().iter().copied().collect(); + for client_id in connected_clients { + if let Some(focused_pane_id_for_client) = self.active_panes.get(&client_id) { + if all_panes_in_stack.contains(focused_pane_id_for_client) { + self.active_panes + .insert(client_id, pane_id, &mut self.panes); + self.set_pane_active_at(pane_id); + } + } + } + self.set_force_render(); + self.reapply_pane_frames(); + all_panes_in_stack + }, + Err(e) => { + log::error!("Failed to expand pane in stack: {:?}", e); + vec![] + }, + } + } pub fn focus_pane(&mut self, pane_id: PaneId, client_id: ClientId) { if self .panes @@ -485,7 +512,7 @@ impl TiledPanes { .unwrap_or(false) { let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) - .focus_pane(&pane_id); + .expand_pane(&pane_id); self.reapply_pane_frames(); } @@ -826,7 +853,7 @@ impl TiledPanes { .unwrap_or(false) { let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) - .focus_pane(&next_active_pane_id); + .expand_pane(&next_active_pane_id); self.reapply_pane_frames(); } @@ -858,7 +885,7 @@ impl TiledPanes { .unwrap_or(false) { let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) - .focus_pane(&next_active_pane_id); + .expand_pane(&next_active_pane_id); self.reapply_pane_frames(); } for client_id in connected_clients { @@ -1166,7 +1193,7 @@ impl TiledPanes { .unwrap_or(false) { let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) - .focus_pane(&new_position_id); + .expand_pane(&new_position_id); self.reapply_pane_frames(); } @@ -1430,7 +1457,7 @@ impl TiledPanes { .unwrap_or(false) { let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) - .focus_pane(&next_active_pane_id); + .expand_pane(&next_active_pane_id); self.reapply_pane_frames(); } for (client_id, active_pane_id) in active_panes { diff --git a/zellij-server/src/panes/tiled_panes/stacked_panes.rs b/zellij-server/src/panes/tiled_panes/stacked_panes.rs index cc0b0f151..bc5057a5b 100644 --- a/zellij-server/src/panes/tiled_panes/stacked_panes.rs +++ b/zellij-server/src/panes/tiled_panes/stacked_panes.rs @@ -102,9 +102,8 @@ impl<'a> StackedPanes<'a> { } Ok(()) } - pub fn focus_pane(&mut self, pane_id: &PaneId) -> Result<()> { - // this function doesn't actually change the focus (since it is controlled elsewhere) - // but rather makes sure pane_id is flexible if it were a one-liner before + pub fn expand_pane(&mut self, pane_id: &PaneId) -> Result<Vec<PaneId>> { + // returns all the pane ids in the stack let err_context = || format!("Failed to focus stacked pane"); let all_stacked_pane_positions = self.positions_in_stack(pane_id).with_context(err_context)?; @@ -158,7 +157,10 @@ impl<'a> StackedPanes<'a> { } } } - Ok(()) + Ok(all_stacked_pane_positions + .iter() + .map(|(pane_id, _pane_position)| *pane_id) + .collect()) } pub fn flexible_pane_id_in_stack(&self, pane_id_in_stack: &PaneId) -> Option<PaneId> { let all_stacked_pane_positions = self.positions_in_stack(pane_id_in_stack).ok()?; diff --git a/zellij-server/src/tab/layout_applier.rs b/zellij-server/src/tab/layout_applier.rs index 04c22fe9a..ef475c07e 100644 --- a/zellij-server/src/tab/layout_applier.rs +++ b/zellij-server/src/tab/layout_applier.rs @@ -138,6 +138,8 @@ impl<'a> LayoutApplier<'a> { Some(position_and_size), ); pane_focuser.set_pane_id_in_focused_location(layout.focus, &pane); + pane_focuser + .set_expanded_stacked_pane(layout.is_expanded_in_stack, &pane); resize_pty!(pane, self.os_api, self.senders, self.character_cell_size)?; self.tiled_panes .add_pane_with_existing_geom(pane.pid(), pane); @@ -161,6 +163,7 @@ impl<'a> LayoutApplier<'a> { Some(position_and_size), ); pane_focuser.set_pane_id_in_focused_location(layout.focus, &pane); + pane_focuser.set_expanded_stacked_pane(layout.is_expanded_in_stack, &pane); re |