summaryrefslogtreecommitdiffstats
path: root/zellij-server/src/panes
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2022-11-23 18:14:24 +0100
committerGitHub <noreply@github.com>2022-11-23 18:14:24 +0100
commitf8fbd8a138f46db4a02084a98bb182f625faea4a (patch)
tree8d7faee691d1691e786827f3803947b8c7fdfbc9 /zellij-server/src/panes
parent00fedafa38daca7a463d3d1b8b29fd74d47327c8 (diff)
fix(panes): focus change when closing and between tabs (#1966)
* fix(panes): do not forget pane focus when switching tabs or closing panes * style(fmt): rustfmt * fix(tests): e2e snapshots
Diffstat (limited to 'zellij-server/src/panes')
-rw-r--r--zellij-server/src/panes/floating_panes/mod.rs28
-rw-r--r--zellij-server/src/panes/tiled_panes/mod.rs23
2 files changed, 42 insertions, 9 deletions
diff --git a/zellij-server/src/panes/floating_panes/mod.rs b/zellij-server/src/panes/floating_panes/mod.rs
index 5eb73f438..3ca7f5726 100644
--- a/zellij-server/src/panes/floating_panes/mod.rs
+++ b/zellij-server/src/panes/floating_panes/mod.rs
@@ -807,14 +807,27 @@ impl FloatingPanes {
.iter()
.map(|(cid, pid)| (*cid, *pid))
.collect();
- let next_active_pane = self.panes.keys().next().copied();
+
+ // find the most recently active pane
+ let mut next_active_pane_candidates: Vec<(&PaneId, &Box<dyn Pane>)> = self
+ .panes
+ .iter()
+ .filter(|(_p_id, p)| p.selectable())
+ .collect();
+ next_active_pane_candidates.sort_by(|(_pane_id_a, pane_a), (_pane_id_b, pane_b)| {
+ pane_a.active_at().cmp(&pane_b.active_at())
+ });
+ let next_active_pane_id = next_active_pane_candidates
+ .last()
+ .map(|(pane_id, _pane)| **pane_id);
+
for (client_id, active_pane_id) in active_panes {
if active_pane_id == pane_id {
- match next_active_pane {
- Some(next_active_pane) => {
+ match next_active_pane_id {
+ Some(next_active_pane_id) => {
self.active_panes
- .insert(client_id, next_active_pane, &mut self.panes);
- self.focus_pane(next_active_pane, client_id);
+ .insert(client_id, next_active_pane_id, &mut self.panes);
+ self.focus_pane(next_active_pane_id, client_id);
},
None => {
self.defocus_pane(pane_id, client_id);
@@ -840,6 +853,11 @@ impl FloatingPanes {
.insert(client_id, pane_id, &mut self.panes);
self.focus_pane_for_all_clients(pane_id);
}
+ pub fn focus_pane_if_client_not_focused(&mut self, pane_id: PaneId, client_id: ClientId) {
+ if self.active_panes.get(&client_id).is_none() {
+ self.focus_pane(pane_id, client_id)
+ }
+ }
pub fn defocus_pane(&mut self, pane_id: PaneId, client_id: ClientId) {
self.z_indices.retain(|p_id| *p_id != pane_id);
self.active_panes.remove(&client_id, &mut self.panes);
diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs
index 96fd2f67d..b1665cc97 100644
--- a/zellij-server/src/panes/tiled_panes/mod.rs
+++ b/zellij-server/src/panes/tiled_panes/mod.rs
@@ -345,6 +345,13 @@ impl TiledPanes {
}
self.reset_boundaries();
}
+ pub fn focus_pane_if_client_not_focused(&mut self, pane_id: PaneId, client_id: ClientId) {
+ log::info!("inside focus_pane_if_client_not_focused");
+ if self.active_panes.get(&client_id).is_none() {
+ log::info!("is none");
+ self.focus_pane(pane_id, client_id)
+ }
+ }
pub fn clear_active_panes(&mut self) {
self.active_panes.clear(&mut self.panes);
self.reset_boundaries();
@@ -999,12 +1006,20 @@ impl TiledPanes {
.iter()
.map(|(cid, pid)| (*cid, *pid))
.collect();
- let next_active_pane_id = self
+
+ // find the most recently active pane
+ let mut next_active_pane_candidates: Vec<(&PaneId, &Box<dyn Pane>)> = self
.panes
.iter()
- .filter(|(p_id, _)| !self.panes_to_hide.contains(p_id))
- .find(|(p_id, p)| **p_id != pane_id && p.selectable())
- .map(|(p_id, _p)| *p_id);
+ .filter(|(p_id, p)| !self.panes_to_hide.contains(p_id) && p.selectable())
+ .collect();
+ next_active_pane_candidates.sort_by(|(_pane_id_a, pane_a), (_pane_id_b, pane_b)| {
+ pane_a.active_at().cmp(&pane_b.active_at())
+ });
+ let next_active_pane_id = next_active_pane_candidates
+ .last()
+ .map(|(pane_id, _pane)| **pane_id);
+
match next_active_pane_id {
Some(next_active_pane) => {
for (client_id, active_pane_id) in active_panes {