Skip to content

Commit

Permalink
chore: Apply cargo format
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanhs committed Dec 30, 2023
1 parent 40e6ee0 commit ff72fe8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
39 changes: 23 additions & 16 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,11 +850,11 @@ impl Grid {

let mut new_cursor_y = self.canonical_line_y_coordinates(cursor_canonical_line_index)
+ (cursor_index_in_canonical_line / new_columns);
let mut saved_cursor_y_coordinates = self.saved_cursor_position.as_ref()
.map(|saved_cursor|
let mut saved_cursor_y_coordinates =
self.saved_cursor_position.as_ref().map(|saved_cursor| {
self.canonical_line_y_coordinates(saved_cursor.y)
+ saved_cursor_index_in_canonical_line.as_ref().unwrap() / new_columns
);
});

// A cursor at EOL has two equivalent positions - end of this line or beginning of
// next. If not already at the beginning of line, bias to EOL so add character logic
Expand All @@ -864,8 +864,8 @@ 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 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 mut new_x = *saved_cursor_index_in_canonical_line % new_columns;
let new_y = saved_cursor_y_coordinates.as_mut().unwrap();
Expand All @@ -874,7 +874,8 @@ impl Grid {
new_x = new_columns
}
new_x
});
},
);

let current_viewport_row_count = self.viewport.len();
match current_viewport_row_count.cmp(&self.height) {
Expand Down Expand Up @@ -926,20 +927,25 @@ 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),
_ => unreachable!(
"saved cursor {:?} {:?}",
saved_cursor_x_coordinates, saved_cursor_y_coordinates
),
}
};
}
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 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 saved_cursor_x_coordinates =
self.saved_cursor_position.as_ref().map(|saved_cursor| saved_cursor.x);
let 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) {
Expand Down Expand Up @@ -990,9 +996,10 @@ 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),
_ => unreachable!(
"saved cursor {:?} {:?}",
saved_cursor_x_coordinates, saved_cursor_y_coordinates
),
}
};
}
Expand Down
23 changes: 16 additions & 7 deletions zellij-server/src/panes/unit/grid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2421,8 +2421,11 @@ fn saved_cursor_across_resize() {
arrow_fonts,
styled_underlines,
);
let mut parse = |s, grid: &mut Grid|
for b in Vec::from(s) { vte_parser.advance(&mut *grid, b) };
let mut parse = |s, grid: &mut Grid| {
for b in Vec::from(s) {
vte_parser.advance(&mut *grid, b)
}
};
let content = "
\rLine 1 >fill to 20_<
\rLine 2 >fill to 20_<
Expand Down Expand Up @@ -2463,8 +2466,11 @@ fn saved_cursor_across_resize_longline() {
arrow_fonts,
styled_underlines,
);
let mut parse = |s, grid: &mut Grid|
for b in Vec::from(s) { vte_parser.advance(&mut *grid, b) };
let mut parse = |s, grid: &mut Grid| {
for b in Vec::from(s) {
vte_parser.advance(&mut *grid, b)
}
};
let content = "
\rLine 1 >fill \u{1b}[sto 20_<";
parse(content, &mut grid);
Expand All @@ -2487,7 +2493,7 @@ fn saved_cursor_across_resize_rewrap() {
let styled_underlines = true;
let mut grid = Grid::new(
4,
4*8,
4 * 8,
Rc::new(RefCell::new(Palette::default())),
terminal_emulator_color_codes,
Rc::new(RefCell::new(LinkHandler::new())),
Expand All @@ -2498,8 +2504,11 @@ fn saved_cursor_across_resize_rewrap() {
arrow_fonts,
styled_underlines,
);
let mut parse = |s, grid: &mut Grid|
for b in Vec::from(s) { vte_parser.advance(&mut *grid, b) };
let mut parse = |s, grid: &mut Grid| {
for b in Vec::from(s) {
vte_parser.advance(&mut *grid, b)
}
};
let content = "
\r12345678123456781234567\u{1b}[s812345678"; // 4*8 chars
parse(content, &mut grid);
Expand Down

0 comments on commit ff72fe8

Please sign in to comment.