Skip to content

Commit

Permalink
Unify viewport transfer: use common variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanhs committed Dec 24, 2023
1 parent 76468ea commit a2fb4a8
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,14 @@ impl Grid {
};
}
if new_rows != self.height {
let mut new_cursor_y = self.cursor.y;
let mut saved_cursor_y_coordinates =
self.saved_cursor_position.as_ref().map(|saved_cursor| saved_cursor.y);

let new_cursor_x = self.cursor.x;
let mut saved_cursor_x_coordinates =
self.saved_cursor_position.as_ref().map(|saved_cursor| saved_cursor.x);

let current_viewport_row_count = self.viewport.len();
match current_viewport_row_count.cmp(&new_rows) {
Ordering::Less => {
Expand All @@ -930,23 +938,22 @@ impl Grid {
new_columns,
);
let rows_pulled = self.viewport.len() - current_viewport_row_count;
self.cursor.y += rows_pulled;
if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
saved_cursor_position.y += rows_pulled
new_cursor_y += rows_pulled;
if let Some(saved_cursor_y_coordinates) = saved_cursor_y_coordinates.as_mut() {
*saved_cursor_y_coordinates += rows_pulled;
};
},
Ordering::Greater => {
let row_count_to_transfer = current_viewport_row_count - new_rows;
if row_count_to_transfer > self.cursor.y {
self.cursor.y = 0;
if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
saved_cursor_position.y = 0
if row_count_to_transfer > new_cursor_y {
new_cursor_y = 0;
if let Some(saved_cursor_y_coordinates) = saved_cursor_y_coordinates.as_mut() {
*saved_cursor_y_coordinates = 0
};
} else {
self.cursor.y -= row_count_to_transfer;
if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
saved_cursor_position.y = saved_cursor_position
.y
new_cursor_y -= row_count_to_transfer;
if let Some(saved_cursor_y_coordinates) = saved_cursor_y_coordinates.as_mut() {
*saved_cursor_y_coordinates = saved_cursor_y_coordinates
.saturating_sub(row_count_to_transfer);
};
}
Expand All @@ -960,6 +967,19 @@ impl Grid {
},
Ordering::Equal => {},
}
self.cursor.y = new_cursor_y;
self.cursor.x = new_cursor_x;
if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
match (saved_cursor_x_coordinates, saved_cursor_y_coordinates) {
(Some(saved_cursor_x_coordinates), Some(saved_cursor_y_coordinates)) => {
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),
}
};
}
self.height = new_rows;
self.width = new_columns;
Expand Down

0 comments on commit a2fb4a8

Please sign in to comment.