diff options
author | Aram Drevekenin <aram@poor.dev> | 2021-09-28 15:41:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 15:41:32 +0200 |
commit | 8b3287c452765c5206dfe22e39d948a6a6662a29 (patch) | |
tree | ea9524f512c62dd10a154b5a6405b26730d1d3ca | |
parent | 9227ff09819d0c26dedf70e7434a1985f4a5a483 (diff) |
fix(compatibility): handle cursor movements outside scroll region (#746)
* fix(compatibility): handle cursor movements outside scroll region
* style(fmt): make clippy happy
4 files changed, 110 insertions, 9 deletions
diff --git a/src/tests/fixtures/move_cursor_below_scroll_region b/src/tests/fixtures/move_cursor_below_scroll_region new file mode 100755 index 000000000..fddccf650 --- /dev/null +++ b/src/tests/fixtures/move_cursor_below_scroll_region @@ -0,0 +1,42 @@ +[0;30r +
1foo +
2foo +
3foo +
4foo +
5foo +
6foo +
7foo +
8foo +
9foo +
10foo +
11foo +
12foo +
13foo +
14foo +
15foo +
16foo +
17foo +
18foo +
19foo +
20foo +
21foo +
22foo +
23foo +
24foo +
25foo +
26foo +
27foo +
28foo +
29foo +
30foo +
31foo +
32foo +
33foo +
34foo +
35foo +[35;0H +
1bar +
2bar +
3bar +
4bar +
5zz
\ No newline at end of file diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs index 2d2354c67..f157b3274 100644 --- a/zellij-server/src/panes/grid.rs +++ b/zellij-server/src/panes/grid.rs @@ -883,14 +883,16 @@ impl Grid { self.viewport.push(new_row); } if self.cursor.y == self.height - 1 { - let row_count_to_transfer = 1; - transfer_rows_from_viewport_to_lines_above( - &mut self.viewport, - &mut self.lines_above, - row_count_to_transfer, - self.width, - ); - self.selection.move_up(1); + if self.scroll_region.is_none() { + let row_count_to_transfer = 1; + transfer_rows_from_viewport_to_lines_above( + &mut self.viewport, + &mut self.lines_above, + row_count_to_transfer, + self.width, + ); + self.selection.move_up(1); + } self.output_buffer.update_all_lines(); } else { self.cursor.y += 1; @@ -1051,7 +1053,11 @@ impl Grid { } else { 0 }; - self.cursor.y = std::cmp::min(scroll_region_bottom, y + y_offset); + if y >= scroll_region_top && y <= scroll_region_bottom { + self.cursor.y = std::cmp::min(scroll_region_bottom, y + y_offset); + } else { + self.cursor.y = std::cmp::min(self.height - 1, y + y_offset); + } self.pad_lines_until(self.cursor.y, pad_character); self.pad_current_line_until(self.cursor.x); } diff --git a/zellij-server/src/panes/unit/grid_tests.rs b/zellij-server/src/panes/unit/grid_tests.rs index 34236f7e8..1ecc10a90 100644 --- a/zellij-server/src/panes/unit/grid_tests.rs +++ b/zellij-server/src/panes/unit/grid_tests.rs @@ -998,3 +998,15 @@ pub fn scroll_up_increase_width_and_scroll_down() { } assert_snapshot!(format!("{:?}", grid)); } + +#[test] +pub fn move_cursor_below_scroll_region() { + let mut vte_parser = vte::Parser::new(); + let mut grid = Grid::new(34, 114, Palette::default()); + let fixture_name = "move_cursor_below_scroll_region"; + let content = read_fixture(fixture_name); + for byte in content { + vte_parser.advance(&mut grid, byte); + } + assert_snapshot!(format!("{:?}", grid)); +} diff --git a/zellij-server/src/panes/unit/snapshots/zellij_server__panes__grid__grid_tests__move_cursor_below_scroll_region.snap b/zellij-server/src/panes/unit/snapshots/zellij_server__panes__grid__grid_tests__move_cursor_below_scroll_region.snap new file mode 100644 index 000000000..ae731f374 --- /dev/null +++ b/zellij-server/src/panes/unit/snapshots/zellij_server__panes__grid__grid_tests__move_cursor_below_scroll_region.snap @@ -0,0 +1,41 @@ +--- +source: zellij-server/src/panes/./unit/grid_tests.rs +expression: "format!(\"{:?}\", grid)" + +--- +00 (C): 7foo +01 (C): 8foo +02 (C): 9foo +03 (C): 10foo +04 (C): 11foo +05 (C): 12foo +06 (C): 13foo +07 (C): 14foo +08 (C): 15foo +09 (C): 16foo +10 (C): 17foo +11 (C): 18foo +12 (C): 19foo +13 (C): 20foo +14 (C): 21foo +15 (C): 22foo +16 (C): 23foo +17 (C): 24foo +18 (C): 25foo +19 (C): 26foo +20 (C): 27foo +21 (C): 28foo +22 (C): 29foo +23 (C): 30foo +24 (C): 31foo +25 (C): 32foo +26 (C): 33foo +27 (C): 34foo +28 (C): 35foo +29 (C): +30 (C): +31 (C): +32 (C): +33 (C): 5zzr +34 (C): + |