summaryrefslogtreecommitdiffstats
path: root/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs
diff options
context:
space:
mode:
Diffstat (limited to 'zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs')
-rw-r--r--zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs46
1 files changed, 45 insertions, 1 deletions
diff --git a/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs b/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs
index 8fc40d2b4..5ee5cf3ca 100644
--- a/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs
+++ b/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs
@@ -3,7 +3,7 @@ use super::pane_resizer::PaneResizer;
use super::stacked_panes::StackedPanes;
use crate::tab::{MIN_TERMINAL_HEIGHT, MIN_TERMINAL_WIDTH};
use crate::{panes::PaneId, tab::Pane};
-use std::cmp::Reverse;
+use std::cmp::{Ordering, Reverse};
use std::collections::{HashMap, HashSet};
use zellij_utils::data::{Direction, Resize, ResizeStrategy};
use zellij_utils::{
@@ -1025,6 +1025,50 @@ impl<'a> TiledPaneGrid<'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 => b.y().cmp(&a.y()),
+ _ => x_comparison,
+ }
+ },
+ Direction::Right => {
+ let x_comparison = b.x().cmp(&a.x());
+ match x_comparison {
+ Ordering::Equal => b.y().cmp(&a.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_above(&self, current_pane_id: &PaneId) -> Option<PaneId> {
let panes = self.panes.borrow();
let current_pane = panes.get(current_pane_id)?;