From cb75b642f7a50ca913db1d8182a80324f2e5b78e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 20 Aug 2022 07:20:07 -0700 Subject: [PATCH] Fixup ActivatePaneDirection to respect edge intersection d2892c6 switched to using recency only, but neglected to verify that the edges of the candidate panes were actually touching, leading to some weird results. This commit uses recency only when the edges intersect, otherwise, scores 0 for the candidate. refs: #2374 --- mux/src/tab.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/mux/src/tab.rs b/mux/src/tab.rs index 5d88a3f81..dfda6d1c6 100644 --- a/mux/src/tab.rs +++ b/mux/src/tab.rs @@ -5,6 +5,7 @@ use crate::{Mux, WindowId}; use bintree::PathBranch; use config::configuration; use config::keyassignment::PaneDirection; +use rangeset::intersects_range; use serde::{Deserialize, Serialize}; use std::cell::{RefCell, RefMut}; use std::collections::HashMap; @@ -1276,31 +1277,51 @@ impl Tab { let recency = self.recency.borrow(); + fn edge_intersects( + active_start: usize, + active_size: usize, + current_start: usize, + current_size: usize, + ) -> bool { + intersects_range( + &(active_start..active_start + active_size), + &(current_start..current_start + current_size), + ) + } + for pane in &panes { let score = match direction { PaneDirection::Right => { - if pane.left == active.left + active.width + 1 { + if pane.left == active.left + active.width + 1 + && edge_intersects(active.top, active.height, pane.top, pane.height) + { 1 + recency.score(pane.index) } else { 0 } } PaneDirection::Left => { - if pane.left + pane.width + 1 == active.left { + if pane.left + pane.width + 1 == active.left + && edge_intersects(active.top, active.height, pane.top, pane.height) + { 1 + recency.score(pane.index) } else { 0 } } PaneDirection::Up => { - if pane.top + pane.height + 1 == active.top { + if pane.top + pane.height + 1 == active.top + && edge_intersects(active.left, active.width, pane.left, pane.width) + { 1 + recency.score(pane.index) } else { 0 } } PaneDirection::Down => { - if active.top + active.height + 1 == pane.top { + if active.top + active.height + 1 == pane.top + && edge_intersects(active.left, active.width, pane.left, pane.width) + { 1 + recency.score(pane.index) } else { 0