diff options
| author | Aram Drevekenin <aram@poor.dev> | 2026-01-27 10:18:31 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-27 10:18:31 +0100 |
| commit | f0a8f4659c825ca8fb34fa6f89ecab414b6c6d3f (patch) | |
| tree | efccf839dfa4bbd36a9713082a7d604a3e5ba874 /zellij-server/src/tab | |
| parent | feat(assets): add svg logo (#4196) (diff) | |
| download | sl0ppij-f0a8f4659c825ca8fb34fa6f89ecab414b6c6d3f.tar.gz sl0ppij-f0a8f4659c825ca8fb34fa6f89ecab414b6c6d3f.tar.xz sl0ppij-f0a8f4659c825ca8fb34fa6f89ecab414b6c6d3f.zip | |
fix: properly occlude cursor in floating pane when pinned pane covers it (#4644)
* fix: properly occlude cursor in floating pane when pinned pane covers it
* add pr
Diffstat (limited to 'zellij-server/src/tab')
| -rw-r--r-- | zellij-server/src/tab/mod.rs | 13 | ||||
| -rw-r--r-- | zellij-server/src/tab/unit/tab_integration_tests.rs | 156 | ||||
| -rw-r--r-- | zellij-server/src/tab/unit/tab_tests.rs | 187 |
3 files changed, 351 insertions, 5 deletions
diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index ab794853..02c26362 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -3057,11 +3057,14 @@ impl Tab { match self .get_active_terminal_cursor_position(client_id) .and_then(|(cursor_position_x, cursor_position_y)| { - // TODO: get active_pane_z_index and pass it to cursor_is_visible so we do the - // right thing if the cursor is in a floating pane - if self.floating_panes.panes_are_visible() { - Some((cursor_position_x, cursor_position_y)) - } else if output.cursor_is_visible(cursor_position_x, cursor_position_y) { + let active_pane_z_index = self + .get_active_pane_id(client_id) + .and_then(|pane_id| self.floating_panes.get_pane_z_index(pane_id)); + if output.cursor_is_visible( + cursor_position_x, + cursor_position_y, + active_pane_z_index, + ) { Some((cursor_position_x, cursor_position_y)) } else { None diff --git a/zellij-server/src/tab/unit/tab_integration_tests.rs b/zellij-server/src/tab/unit/tab_integration_tests.rs index 627af6af..8b109def 100644 --- a/zellij-server/src/tab/unit/tab_integration_tests.rs +++ b/zellij-server/src/tab/unit/tab_integration_tests.rs @@ -10050,3 +10050,159 @@ fn borderless_pinned_floating_pane() { ); assert_snapshot!(snapshot); } + +#[test] +fn cursor_hidden_when_floating_pane_is_under_pinned_pane() { + // Test that cursor is correctly hidden when focused on a floating pane that's under a pinned pane + let size = Size { + cols: 121, + rows: 20, + }; + let client_id = 1; + let mut tab = create_new_tab(size, ModeInfo::default()); + let mut output = Output::default(); + + // Create first floating pane (will be underneath) + let bottom_pane_coordinates = FloatingPaneCoordinates { + x: Some(PercentOrFixed::Fixed(10)), + y: Some(PercentOrFixed::Fixed(5)), + width: Some(PercentOrFixed::Fixed(40)), + height: Some(PercentOrFixed::Fixed(10)), + pinned: Some(false), + borderless: Some(false), + }; + + tab.new_floating_pane( + PaneId::Terminal(2), + None, + None, + false, + true, + Some(bottom_pane_coordinates), + None, + ) + .unwrap(); + + // Create overlapping pinned pane on top + let top_pane_coordinates = FloatingPaneCoordinates { + x: Some(PercentOrFixed::Fixed(15)), + y: Some(PercentOrFixed::Fixed(6)), + width: Some(PercentOrFixed::Fixed(30)), + height: Some(PercentOrFixed::Fixed(8)), + pinned: Some(true), + borderless: Some(false), + }; + + tab.new_floating_pane( + PaneId::Terminal(3), + None, + None, + false, + true, + Some(top_pane_coordinates), + None, + ) + .unwrap(); + + // Add some text to both panes so we can see them + tab.handle_pty_bytes(2, Vec::from("Bottom floating pane".as_bytes())) + .unwrap(); + tab.handle_pty_bytes(3, Vec::from("Top pinned pane".as_bytes())) + .unwrap(); + + // Explicitly focus the bottom floating pane (PaneId::Terminal(2)) + // Use move_focus_left to switch from pane 3 to pane 2 + tab.move_focus_left(client_id).unwrap(); + + // Render + tab.render(&mut output, None).unwrap(); + let (_snapshot, cursor_coordinates) = take_snapshot_and_cursor_position( + output.serialize().unwrap().get(&client_id).unwrap(), + size.rows, + size.cols, + Palette::default(), + ); + + // The cursor should be hidden because the focused pane (2) is under the pinned pane (3) + // and the cursor position falls within the overlapping area + assert_eq!( + cursor_coordinates, None, + "Cursor should be hidden when focused floating pane is under a pinned pane that covers it" + ); +} + +#[test] +fn cursor_visible_when_pinned_pane_is_focused() { + // Test that cursor is visible when focused on a pinned pane that's on top + let size = Size { + cols: 121, + rows: 20, + }; + let client_id = 1; + let mut tab = create_new_tab(size, ModeInfo::default()); + let mut output = Output::default(); + + // Create first floating pane (will be underneath) + let bottom_pane_coordinates = FloatingPaneCoordinates { + x: Some(PercentOrFixed::Fixed(10)), + y: Some(PercentOrFixed::Fixed(5)), + width: Some(PercentOrFixed::Fixed(40)), + height: Some(PercentOrFixed::Fixed(10)), + pinned: Some(false), + borderless: Some(false), + }; + + tab.new_floating_pane( + PaneId::Terminal(2), + None, + None, + false, + true, + Some(bottom_pane_coordinates), + None, + ) + .unwrap(); + + // Create overlapping pinned pane on top + let top_pane_coordinates = FloatingPaneCoordinates { + x: Some(PercentOrFixed::Fixed(15)), + y: Some(PercentOrFixed::Fixed(6)), + width: Some(PercentOrFixed::Fixed(30)), + height: Some(PercentOrFixed::Fixed(8)), + pinned: Some(true), + borderless: Some(false), + }; + + tab.new_floating_pane( + PaneId::Terminal(3), + None, + None, + false, + true, + Some(top_pane_coordinates), + None, + ) + .unwrap(); + + // Add some text to both panes + tab.handle_pty_bytes(2, Vec::from("Bottom floating pane".as_bytes())) + .unwrap(); + tab.handle_pty_bytes(3, Vec::from("Top pinned pane".as_bytes())) + .unwrap(); + + // The pinned pane should be focused by default (last created) + // Render + tab.render(&mut output, None).unwrap(); + let (_snapshot, cursor_coordinates) = take_snapshot_and_cursor_position( + output.serialize().unwrap().get(&client_id).unwrap(), + size.rows, + size.cols, + Palette::default(), + ); + + // The cursor should be visible because the focused pane is the pinned pane on top + assert!( + cursor_coordinates.is_some(), + "Cursor should be visible when focused on pinned pane that's on top" + ); +} diff --git a/zellij-server/src/tab/unit/tab_tests.rs b/zellij-server/src/tab/unit/tab_tests.rs index fec63764..eea12a55 100644 --- a/zellij-server/src/tab/unit/tab_tests.rs +++ b/zellij-server/src/tab/unit/tab_tests.rs @@ -15066,3 +15066,190 @@ fn correctly_resize_frameless_panes_on_pane_close() { let content_size = (pane.get_content_columns(), pane.get_content_rows()); assert_eq!(content_size, (cols, rows)); } + +#[test] +fn floating_pane_z_index_is_tracked() { + let size = Size { + cols: 121, + rows: 20, + }; + let stacked_resize = false; + let mut tab = create_new_tab(size, stacked_resize); + let _client_id = 1; + + // Create first floating pane (should_float = true means it will be a floating pane) + tab.new_floating_pane(PaneId::Terminal(2), None, None, false, true, None, None) + .unwrap(); + + // Create second floating pane + tab.new_floating_pane(PaneId::Terminal(3), None, None, false, true, None, None) + .unwrap(); + + // Verify z-indices exist and are different + let z_index_pane2 = tab.floating_panes.get_pane_z_index(PaneId::Terminal(2)); + let z_index_pane3 = tab.floating_panes.get_pane_z_index(PaneId::Terminal(3)); + + assert!( + z_index_pane2.is_some(), + "First floating pane should have a z-index" + ); + assert!( + z_index_pane3.is_some(), + "Second floating pane should have a z-index" + ); + assert_ne!( + z_index_pane2, z_index_pane3, + "Different panes should have different z-indices" + ); +} + +#[test] +fn pinned_floating_pane_has_higher_z_index() { + let size = Size { + cols: 121, + rows: 20, + }; + let stacked_resize = false; + let mut tab = create_new_tab(size, stacked_resize); + let _client_id = 1; + + // Create first floating pane (will be unpinned) + tab.new_floating_pane(PaneId::Terminal(2), None, None, false, true, None, None) + .unwrap(); + + // Create second floating pane and pin it + tab.new_floating_pane(PaneId::Terminal(3), None, None, false, true, None, None) + .unwrap(); + tab.set_floating_pane_pinned(PaneId::Terminal(3), true); + + // Get z-indices + let z_index_unpinned = tab + .floating_panes + .get_pane_z_index(PaneId::Terminal(2)) + .expect("Unpinned pane should have z-index"); + let z_index_pinned = tab + .floating_panes + .get_pane_z_index(PaneId::Terminal(3)) + .expect("Pinned pane should have z-index"); + + assert!( + z_index_pinned > z_index_unpinned, + "Pinned pane should have higher z-index than unpinned pane (pinned: {}, unpinned: {})", + z_index_pinned, + z_index_unpinned + ); +} + +#[test] +fn pinned_pane_z_index_higher_than_regular_floating_panes() { + let size = Size { + cols: 121, + rows: 20, + }; + let stacked_resize = false; + let mut tab = create_new_tab(size, stacked_resize); + let _client_id = 1; + + // Create first floating pane + tab.new_floating_pane(PaneId::Terminal(2), None, None, false, true, None, None) + .unwrap(); + + // Create second floating pane + tab.new_floating_pane(PaneId::Terminal(3), None, None, false, true, None, None) + .unwrap(); + + // Pin the second pane so it's on top + tab.set_floating_pane_pinned(PaneId::Terminal(3), true); + + // Verify that get_pane_z_index returns correct values for both panes + let z_index_bottom = tab.floating_panes.get_pane_z_index(PaneId::Terminal(2)); + let z_index_top = tab.floating_panes.get_pane_z_index(PaneId::Terminal(3)); + + assert!( + z_index_bottom.is_some(), + "Regular floating pane should have z-index" + ); + assert!( + z_index_top.is_some(), + "Pinned floating pane should have z-index" + ); + assert!( + z_index_top.unwrap() > z_index_bottom.unwrap(), + "Pinned pane should have higher z-index than regular floating pane (pinned: {}, regular: {})", + z_index_top.unwrap(), + z_index_bottom.unwrap() + ); +} + +#[test] +fn active_pane_z_index_retrieved_for_cursor_visibility() { + let size = Size { + cols: 121, + rows: 20, + }; + let stacked_resize = false; + let mut tab = create_new_tab(size, stacked_resize); + let client_id = 1; + + // Start with tiled panes - active pane should not have z-index + let active_pane_id_tiled = tab.get_active_pane_id(client_id).unwrap(); + let z_index_tiled = tab.floating_panes.get_pane_z_index(active_pane_id_tiled); + assert!( + z_index_tiled.is_none(), + "Tiled pane should not have z-index in floating panes" + ); + + // Create a floating pane + tab.new_floating_pane(PaneId::Terminal(2), None, None, false, true, None, None) + .unwrap(); + + // Active pane should now have a z-index + let active_pane_id_floating = tab.get_active_pane_id(client_id).unwrap(); + let z_index_floating = tab.floating_panes.get_pane_z_index(active_pane_id_floating); + assert!( + z_index_floating.is_some(), + "Active floating pane should have a z-index" + ); +} + +#[test] +fn get_pane_z_index_returns_none_for_nonexistent_pane() { + let size = Size { + cols: 121, + rows: 20, + }; + let stacked_resize = false; + let mut tab = create_new_tab(size, stacked_resize); + let _client_id = 1; + + // Create two floating panes + tab.new_floating_pane(PaneId::Terminal(2), None, None, false, true, None, None) + .unwrap(); + tab.new_floating_pane(PaneId::Terminal(3), None, None, false, true, None, None) + .unwrap(); + + // Query for a pane that doesn't exist + let z_index_nonexistent = tab.floating_panes.get_pane_z_index(PaneId::Terminal(999)); + + assert!( + z_index_nonexistent.is_none(), + "Non-existent pane should return None for z-index" + ); + + // Query for existing panes + let z_index_2 = tab.floating_panes.get_pane_z_index(PaneId::Terminal(2)); + let z_index_3 = tab.floating_panes.get_pane_z_index(PaneId::Terminal(3)); + + assert!( + z_index_2.is_some(), + "Existing floating pane 2 should return Some for z-index" + ); + assert!( + z_index_3.is_some(), + "Existing floating pane 3 should return Some for z-index" + ); + assert_ne!( + z_index_2, z_index_3, + "Different floating panes should have different z-indices" + ); +} |
