Skip to content

Commit

Permalink
feat: fullscreen focus swapping (#1515)
Browse files Browse the repository at this point in the history
  • Loading branch information
nacairns1 authored Jun 16, 2022
1 parent dc7f07a commit f285047
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 34 deletions.
13 changes: 13 additions & 0 deletions zellij-server/src/panes/tiled_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
20 changes: 18 additions & 2 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
83 changes: 51 additions & 32 deletions zellij-server/src/tab/unit/tab_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}

Expand Down

0 comments on commit f285047

Please sign in to comment.