diff --git a/src/tests/e2e/snapshots/zellij__tests__e2e__cases__start_without_pane_frames.snap b/src/tests/e2e/snapshots/zellij__tests__e2e__cases__start_without_pane_frames.snap index 25731ffeb6..b8fdc86de7 100644 --- a/src/tests/e2e/snapshots/zellij__tests__e2e__cases__start_without_pane_frames.snap +++ b/src/tests/e2e/snapshots/zellij__tests__e2e__cases__start_without_pane_frames.snap @@ -1,11 +1,11 @@ --- source: src/tests/e2e/cases.rs -assertion_line: 1194 +assertion_line: 1326 expression: last_snapshot --- Zellij (e2e-test)  Tab #1  $ │$ █ - │ +$ │ │ │ │ diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs index 377f05f6e8..84c6d4f01c 100644 --- a/zellij-server/src/panes/grid.rs +++ b/zellij-server/src/panes/grid.rs @@ -619,7 +619,7 @@ impl Grid { cursor_canonical_line_index = i; } if i == self.cursor.y { - let line_wraps = self.cursor.y - cursor_canonical_line_index; + let line_wraps = self.cursor.y.saturating_sub(cursor_canonical_line_index); cursor_index_in_canonical_line = (line_wraps * self.width) + self.cursor.x; break; } @@ -860,18 +860,27 @@ impl Grid { new_cursor_y -= 1; new_cursor_x = new_columns } - let saved_cursor_x_coordinates = saved_cursor_index_in_canonical_line.as_ref().map( - |saved_cursor_index_in_canonical_line| { - let x = self.saved_cursor_position.as_ref().unwrap().x; + let saved_cursor_x_coordinates = match ( + saved_cursor_index_in_canonical_line.as_ref(), + self.saved_cursor_position.as_mut(), + saved_cursor_y_coordinates.as_mut(), + ) { + ( + Some(saved_cursor_index_in_canonical_line), + Some(saved_cursor_position), + Some(saved_cursor_y_coordinates), + ) => { + let x = saved_cursor_position.x; let mut new_x = *saved_cursor_index_in_canonical_line % new_columns; - let new_y = saved_cursor_y_coordinates.as_mut().unwrap(); + let new_y = saved_cursor_y_coordinates; if x != 0 && new_x == 0 { - *new_y -= 1; + *new_y = new_y.saturating_sub(1); new_x = new_columns } - new_x + Some(new_x) }, - ); + _ => None, + }; Some(( new_cursor_y, @@ -958,14 +967,14 @@ impl Grid { saved_cursor_position.x = saved_cursor_x_coordinates; saved_cursor_position.y = saved_cursor_y_coordinates; }, - _ => unreachable!( - "saved cursor {:?} {:?}", - saved_cursor_x_coordinates, saved_cursor_y_coordinates + _ => log::error!( + "invalid state - cannot set saved cursor to {:?} {:?}", + saved_cursor_x_coordinates, + saved_cursor_y_coordinates ), } }; } - self.height = new_rows; self.width = new_columns; if self.scroll_region.is_some() {