aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornacairns1 <94420090+nacairns1@users.noreply.github.com>2022-06-16 09:24:10 -0400
committerGitHub <noreply@github.com>2022-06-16 15:24:10 +0200
commitf285047fd3a908e9fd401e0bbcbf26cb40da1750 (patch)
treecddb69c988352379c878ffe71246157ce6b6378d
parentdocs(changelog): fix `WriteChars` action (diff)
downloadsl0ppij-f285047fd3a908e9fd401e0bbcbf26cb40da1750.tar.gz
sl0ppij-f285047fd3a908e9fd401e0bbcbf26cb40da1750.tar.xz
sl0ppij-f285047fd3a908e9fd401e0bbcbf26cb40da1750.zip
feat: fullscreen focus swapping (#1515)
-rw-r--r--zellij-server/src/panes/tiled_panes/mod.rs13
-rw-r--r--zellij-server/src/tab/mod.rs20
-rw-r--r--zellij-server/src/tab/unit/tab_tests.rs83
3 files changed, 82 insertions, 34 deletions
diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs
index 7a6d3dc4..e0469b13 100644
--- a/zellij-server/src/panes/tiled_panes/mod.rs
+++ b/zellij-server/src/panes/tiled_panes/mod.rs
@@ -1082,6 +1082,19 @@ impl TiledPanes {
}
}
}
+
+ pub fn switch_next_pane_fullscreen(&mut self, client_id: ClientId) {
+ self.unset_fullscreen();
+ self.focus_next_pane(client_id);
+ self.toggle_active_pane_fullscreen(client_id);
+ }
+
+ pub fn switch_prev_pane_fullscreen(&mut self, client_id: ClientId) {
+ self.unset_fullscreen();
+ self.focus_previous_pane(client_id);
+ self.toggle_active_pane_fullscreen(client_id);
+ }
+
pub fn panes_to_hide_count(&self) -> usize {
self.panes_to_hide.len()
}
diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs
index 5962bf9b..b7fb2365 100644
--- a/zellij-server/src/tab/mod.rs
+++ b/zellij-server/src/tab/mod.rs
@@ -989,6 +989,18 @@ impl Tab {
pub fn are_floating_panes_visible(&self) -> bool {
self.floating_panes.panes_are_visible()
}
+ pub fn switch_next_pane_fullscreen(&mut self, client_id: ClientId) {
+ if !self.is_fullscreen_active() {
+ return;
+ }
+ self.tiled_panes.switch_next_pane_fullscreen(client_id);
+ }
+ pub fn switch_prev_pane_fullscreen(&mut self, client_id: ClientId) {
+ if !self.is_fullscreen_active() {
+ return;
+ }
+ self.tiled_panes.switch_next_pane_fullscreen(client_id);
+ }
pub fn set_force_render(&mut self) {
self.tiled_panes.set_force_render();
self.floating_panes.set_force_render();
@@ -1221,6 +1233,7 @@ impl Tab {
return;
}
if self.tiled_panes.fullscreen_is_active() {
+ self.switch_next_pane_fullscreen(client_id);
return;
}
self.tiled_panes.focus_next_pane(client_id);
@@ -1230,6 +1243,7 @@ impl Tab {
return;
}
if self.tiled_panes.fullscreen_is_active() {
+ self.switch_prev_pane_fullscreen(client_id);
return;
}
self.tiled_panes.focus_previous_pane(client_id);
@@ -1246,7 +1260,8 @@ impl Tab {
return false;
}
if self.tiled_panes.fullscreen_is_active() {
- return false;
+ self.switch_next_pane_fullscreen(client_id);
+ return true;
}
self.tiled_panes.move_focus_left(client_id)
}
@@ -1295,7 +1310,8 @@ impl Tab {
return false;
}
if self.tiled_panes.fullscreen_is_active() {
- return false;
+ self.switch_next_pane_fullscreen(client_id);
+ return true;
}
self.tiled_panes.move_focus_right(client_id)
}
diff --git a/zellij-server/src/tab/unit/tab_tests.rs b/zellij-server/src/tab/unit/tab_tests.rs
index cec8fa2b..6cc52219 100644
--- a/zellij-server/src/tab/unit/tab_tests.rs
+++ b/zellij-server/src/tab/unit/tab_tests.rs
@@ -670,45 +670,64 @@ pub fn toggle_focused_pane_fullscreen() {
}
#[test]
-pub fn move_focus_is_disabled_in_fullscreen() {
+fn switch_to_next_pane_fullscreen() {
let size = Size {
cols: 121,
rows: 20,
};
- let mut tab = create_new_tab(size);
- for i in 2..5 {
- let new_pane_id = PaneId::Terminal(i);
- tab.new_pane(new_pane_id, Some(1));
- }
- tab.toggle_active_pane_fullscreen(1);
- tab.move_focus_left(1);
- assert_eq!(
- tab.tiled_panes.panes.get(&PaneId::Terminal(4)).unwrap().x(),
- 0,
- "Pane x is on screen edge"
- );
+
+ let mut active_tab = create_new_tab(size);
+
+ active_tab.new_pane(PaneId::Terminal(1), Some(1));
+ active_tab.new_pane(PaneId::Terminal(2), Some(1));
+ active_tab.new_pane(PaneId::Terminal(3), Some(1));
+ active_tab.new_pane(PaneId::Terminal(4), Some(1));
+ active_tab.toggle_active_pane_fullscreen(1);
+
+ // order is now 1 ->2 -> 3 -> 4 due to how new panes are inserted
+
+ active_tab.switch_next_pane_fullscreen(1);
+ active_tab.switch_next_pane_fullscreen(1);
+ active_tab.switch_next_pane_fullscreen(1);
+ active_tab.switch_next_pane_fullscreen(1);
+
+ // position should now be back in terminal 4.
+
assert_eq!(
- tab.tiled_panes.panes.get(&PaneId::Terminal(4)).unwrap().y(),
- 0,
- "Pane y is on screen edge"
- );
- assert_eq!(
- tab.tiled_panes
- .panes
- .get(&PaneId::Terminal(4))
- .unwrap()
- .cols(),
- 121,
- "Pane cols match fullscreen cols"
+ active_tab.get_active_pane_id(1).unwrap(),
+ PaneId::Terminal(4),
+ "Active pane did not switch in fullscreen mode"
);
+}
+
+#[test]
+fn switch_to_prev_pane_fullscreen() {
+ let size = Size {
+ cols: 121,
+ rows: 20,
+ };
+ let mut active_tab = create_new_tab(size);
+
+ //testing four consecutive switches in fullscreen mode
+
+ active_tab.new_pane(PaneId::Terminal(1), Some(1));
+ active_tab.new_pane(PaneId::Terminal(2), Some(1));
+ active_tab.new_pane(PaneId::Terminal(3), Some(1));
+ active_tab.new_pane(PaneId::Terminal(4), Some(1));
+ active_tab.toggle_active_pane_fullscreen(1);
+ // order is now 1 2 3 4
+
+ active_tab.switch_prev_pane_fullscreen(1);
+ active_tab.switch_prev_pane_fullscreen(1);
+ active_tab.switch_prev_pane_fullscreen(1);
+ active_tab.switch_prev_pane_fullscreen(1);
+
+ // the position should now be in Terminal 4.
+
assert_eq!(
- tab.tiled_panes
- .panes
- .get(&PaneId::Terminal(4))
- .unwrap()
- .rows(),
- 20,
- "Pane rows match fullscreen rows"
+ active_tab.get_active_pane_id(1).unwrap(),
+ PaneId::Terminal(4),
+ "Active pane did not switch in fullscreen mode"
);
}