Skip to content

Commit

Permalink
fix(compatibility): handle cursor movements outside scroll region (#746)
Browse files Browse the repository at this point in the history
* fix(compatibility): handle cursor movements outside scroll region

* style(fmt): make clippy happy
  • Loading branch information
imsnif authored Sep 28, 2021
1 parent 9227ff0 commit 8b3287c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 9 deletions.
42 changes: 42 additions & 0 deletions src/tests/fixtures/move_cursor_below_scroll_region
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

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

1bar
2bar
3bar
4bar
5zz
Expand Down
24 changes: 15 additions & 9 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 12 additions & 0 deletions zellij-server/src/panes/unit/grid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Original file line number Diff line number Diff line change
@@ -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):

0 comments on commit 8b3287c

Please sign in to comment.