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/output | |
| 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/output')
| -rw-r--r-- | zellij-server/src/output/mod.rs | 18 | ||||
| -rw-r--r-- | zellij-server/src/output/unit/output_tests.rs | 134 |
2 files changed, 145 insertions, 7 deletions
diff --git a/zellij-server/src/output/mod.rs b/zellij-server/src/output/mod.rs index 180514ae..5ca283a7 100644 --- a/zellij-server/src/output/mod.rs +++ b/zellij-server/src/output/mod.rs @@ -595,11 +595,16 @@ impl Output { self.client_character_chunks.values().any(|c| !c.is_empty()) || self.sixel_chunks.values().any(|c| !c.is_empty()) } - pub fn cursor_is_visible(&mut self, cursor_x: usize, cursor_y: usize) -> bool { + pub fn cursor_is_visible( + &mut self, + cursor_x: usize, + cursor_y: usize, + z_index: Option<usize>, + ) -> bool { self.cursor_coordinates = Some((cursor_x, cursor_y)); self.floating_panes_stack .as_ref() - .map(|s| s.cursor_is_visible(cursor_x, cursor_y)) + .map(|s| s.cursor_is_visible(cursor_x, cursor_y, z_index)) .unwrap_or(true) } pub fn add_pane_contents( @@ -910,8 +915,13 @@ impl FloatingPanesStack { } uncovered_chunks } - pub fn cursor_is_visible(&self, cursor_x: usize, cursor_y: usize) -> bool { - let z_index = 0; // TODO: receive z_index + pub fn cursor_is_visible( + &self, + cursor_x: usize, + cursor_y: usize, + z_index: Option<usize>, + ) -> bool { + let z_index = z_index.map(|z| z + 1).unwrap_or(0); // +1 because we only check panes above the active pane let panes_to_check = self.layers.iter().skip(z_index); for pane_geom in panes_to_check { let pane_top_edge = pane_geom.y; diff --git a/zellij-server/src/output/unit/output_tests.rs b/zellij-server/src/output/unit/output_tests.rs index 4a25748d..bb0bb664 100644 --- a/zellij-server/src/output/unit/output_tests.rs +++ b/zellij-server/src/output/unit/output_tests.rs @@ -508,7 +508,7 @@ fn test_serialize_with_size_hides_cursor_when_cropped() { let max_size = Some(Size { rows: 10, cols: 20 }); // Set cursor outside max_size - output.cursor_is_visible(25, 5); + output.cursor_is_visible(25, 5, None); let chunk = create_character_chunk_from_str("Test", 0, 0); output @@ -796,18 +796,146 @@ fn test_cursor_is_visible_with_floating_panes() { // Cursor inside pane bounds assert!( - !stack.cursor_is_visible(7, 7), + !stack.cursor_is_visible(7, 7, None), "Cursor should not be visible when covered by pane" ); // Cursor outside pane bounds assert!( - stack.cursor_is_visible(20, 20), + stack.cursor_is_visible(20, 20, None), "Cursor should be visible when not covered by pane" ); } #[test] +fn test_cursor_visibility_with_z_index_bottom_layer() { + // Two overlapping panes: bottom at (5,5) and top at (5,5) + let bottom_pane = create_pane_geom(5, 5, 10, 10); + let top_pane = create_pane_geom(5, 5, 10, 10); + + let stack = FloatingPanesStack { + layers: vec![bottom_pane, top_pane], + }; + + // Cursor at position (7,7) in the bottom layer (z-index 0) + // Should be hidden because there's a pane above it (z-index 1) at the same position + assert!( + !stack.cursor_is_visible(7, 7, Some(0)), + "Cursor in bottom layer should be hidden by pane above it" + ); +} + +#[test] +fn test_cursor_visibility_with_z_index_top_layer() { + // Two overlapping panes: bottom at (5,5) and top at (5,5) + let bottom_pane = create_pane_geom(5, 5, 10, 10); + let top_pane = create_pane_geom(5, 5, 10, 10); + + let stack = FloatingPanesStack { + layers: vec![bottom_pane, top_pane], + }; + + // Cursor at position (7,7) in the top layer (z-index 1) + // Should be visible even though there's a pane below it at the same position + assert!( + stack.cursor_is_visible(7, 7, Some(1)), + "Cursor in top layer should be visible (not affected by panes below)" + ); +} + +#[test] +fn test_cursor_visibility_with_multiple_layers() { + // Three panes stacked vertically with different layers + // Layer 0 (bottom): pane at (5,5) + // Layer 1 (middle): pane at (10,10) + // Layer 2 (top): pane at (5,5) - overlaps with layer 0 + let layer0_pane = create_pane_geom(5, 5, 10, 10); + let layer1_pane = create_pane_geom(10, 10, 10, 10); + let layer2_pane = create_pane_geom(5, 5, 10, 10); + + let stack = FloatingPanesStack { + layers: vec![layer0_pane, layer1_pane, layer2_pane], + }; + + // Cursor at (7,7) in layer 0 - should be hidden by layer 2 + assert!( + !stack.cursor_is_visible(7, 7, Some(0)), + "Cursor in layer 0 should be hidden by layer 2 above it" + ); + + // Cursor at (16,16) in layer 1 - should be visible (layer 2 doesn't cover this position) + // Layer 1 is at (10,10) size 10x10, so covers (10,10) to (19,19) + // Layer 2 is at (5,5) size 10x10, so covers (5,5) to (14,14) + // Position (16,16) is inside layer 1 but outside layer 2 + assert!( + stack.cursor_is_visible(16, 16, Some(1)), + "Cursor in layer 1 should be visible when not covered by layers above" + ); + + // Cursor at (7,7) in layer 2 - should be visible (no layers above) + assert!( + stack.cursor_is_visible(7, 7, Some(2)), + "Cursor in top layer should always be visible" + ); +} + +#[test] +fn test_cursor_visibility_pinned_pane_over_floating() { + // Simulates a floating pane (z-index 0) with a pinned pane (z-index 1) on top + // Both panes overlap at the same position + let floating_pane = create_pane_geom(10, 10, 20, 20); + let mut pinned_pane = create_pane_geom(10, 10, 20, 20); + pinned_pane.is_pinned = true; + + let stack = FloatingPanesStack { + layers: vec![floating_pane, pinned_pane], + }; + + // Cursor in the floating pane (z-index 0) at position covered by pinned pane + assert!( + !stack.cursor_is_visible(15, 15, Some(0)), + "Cursor in floating pane should be hidden when covered by pinned pane above" + ); + + // Cursor in the pinned pane (z-index 1) at the same position + assert!( + stack.cursor_is_visible(15, 15, Some(1)), + "Cursor in pinned pane should be visible" + ); +} + +#[test] +fn test_cursor_visibility_partial_overlap() { + // Two panes with partial overlap + // Layer 0: pane at (0, 0) size 10x10 + // Layer 1: pane at (5, 5) size 10x10 (overlaps bottom-right of layer 0) + let layer0_pane = create_pane_geom(0, 0, 10, 10); + let layer1_pane = create_pane_geom(5, 5, 10, 10); + + let stack = FloatingPanesStack { + layers: vec![layer0_pane, layer1_pane], + }; + + // Cursor at (2,2) in layer 0 - not covered by layer 1, should be visible + assert!( + stack.cursor_is_visible(2, 2, Some(0)), + "Cursor in non-overlapping area should be visible" + ); + + // Cursor at (7,7) in layer 0 - covered by layer 1, should be hidden + assert!( + !stack.cursor_is_visible(7, 7, Some(0)), + "Cursor in overlapping area should be hidden by pane above" + ); + + // Cursor at (7,7) in layer 1 - should be visible (top layer) + assert!( + stack.cursor_is_visible(7, 7, Some(1)), + "Cursor in top layer should be visible in overlapping area" + ); +} + +#[test] fn test_output_buffer_update_line() { let mut buffer = OutputBuffer::default(); buffer.clear(); // Clear the initial "update all lines" state |
