diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-03-15 17:00:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-15 17:00:16 +0100 |
commit | c0dd1ba1abb5796508d805129092ca7350d143e0 (patch) | |
tree | de55ab295e576d115878801f477f5eb7f5f81f76 /zellij-server/src/panes/floating_panes/floating_pane_grid.rs | |
parent | 96b3ce29a25d966eb6e37bc8d2849a1ce05e1c15 (diff) |
fix(screen): focus pane on screen edge when moving pane focus offtab (#2293)
* fix(screen): focus pane on proper edge when switching tabs through pane switch
* style(fmt): rustfmt
Diffstat (limited to 'zellij-server/src/panes/floating_panes/floating_pane_grid.rs')
-rw-r--r-- | zellij-server/src/panes/floating_panes/floating_pane_grid.rs | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/zellij-server/src/panes/floating_panes/floating_pane_grid.rs b/zellij-server/src/panes/floating_panes/floating_pane_grid.rs index afeecc8d2..b8472dfc5 100644 --- a/zellij-server/src/panes/floating_panes/floating_pane_grid.rs +++ b/zellij-server/src/panes/floating_panes/floating_pane_grid.rs @@ -2,7 +2,7 @@ use crate::tab::{MIN_TERMINAL_HEIGHT, MIN_TERMINAL_WIDTH}; use crate::{panes::PaneId, tab::Pane}; use std::cmp::Ordering; use std::collections::HashMap; -use zellij_utils::data::ResizeStrategy; +use zellij_utils::data::{Direction, ResizeStrategy}; use zellij_utils::errors::prelude::*; use zellij_utils::pane_size::{Dimension, PaneGeom, Size, Viewport}; @@ -625,6 +625,50 @@ impl<'a> FloatingPaneGrid<'a> { .copied(); next_index } + pub fn pane_id_on_edge(&self, direction: Direction) -> Option<PaneId> { + let panes = self.panes.borrow(); + let panes: Vec<(PaneId, &&mut Box<dyn Pane>)> = panes + .iter() + .filter(|(_, p)| p.selectable()) + .map(|(p_id, p)| (*p_id, p)) + .collect(); + let next_index = panes + .iter() + .enumerate() + .max_by(|(_, (_, a)), (_, (_, b))| match direction { + Direction::Left => { + let x_comparison = a.x().cmp(&b.x()); + match x_comparison { + Ordering::Equal => a.y().cmp(&b.y()), + _ => x_comparison, + } + }, + Direction::Right => { + let x_comparison = b.x().cmp(&a.x()); + match x_comparison { + Ordering::Equal => a.y().cmp(&b.y()), + _ => x_comparison, + } + }, + Direction::Up => { + let y_comparison = a.y().cmp(&b.y()); + match y_comparison { + Ordering::Equal => a.x().cmp(&b.x()), + _ => y_comparison, + } + }, + Direction::Down => { + let y_comparison = b.y().cmp(&a.y()); + match y_comparison { + Ordering::Equal => b.x().cmp(&a.x()), + _ => y_comparison, + } + }, + }) + .map(|(_, (pid, _))| pid) + .copied(); + next_index + } pub fn next_selectable_pane_id_below(&self, current_pane_id: &PaneId) -> Option<PaneId> { let panes = self.panes.borrow(); let current_pane = panes.get(current_pane_id)?; |