1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00

term: improve cursor/viewport positioning on resize

This seems to make our resize behavior a bit nicer and more
consistent with eg: xterm.

Previously we'd consider the previously existing scrollback
as immutable and prefer to add excess blank lines of padding
when making the window taller.

In practice that meant that content would scroll back when
making the window taller, which is annoying.

This commit removes that constraint and instead will prefer
to maintain the cursor position relative to the top of the
viewport when the size changes.

refs: #138
This commit is contained in:
Wez Furlong 2020-10-28 22:50:50 -07:00
parent 92bdc4a3b0
commit 75ce0fc822

View File

@ -195,28 +195,18 @@ impl Screen {
self.lines.push_back(Line::with_width(physical_cols));
}
let vis_cursor_y = cursor
.y
.saturating_add(cursor_y as i64)
.saturating_sub(cursor_phys as i64)
.max(0);
// We need to ensure that the bottom of the screen has sufficient lines;
// we use simple subtraction of physical_rows from the bottom of the lines
// array to define the visible region. Our resize operation may have
// temporarily violated that, which can result in the cursor unintentionally
// moving up into the scrollback and damaging the output
let required_num_rows_after_cursor = physical_rows.saturating_sub(vis_cursor_y as usize);
let actual_num_rows_after_cursor = self.lines.len().saturating_sub(cursor_y);
for _ in actual_num_rows_after_cursor..required_num_rows_after_cursor {
self.lines.push_back(Line::with_width(physical_cols));
}
// Compute the new cursor location; this is logically the inverse
// of the phys_row() function, but given the revised cursor_y
// (the rewrap adjusted physical row of the cursor). This
// computes its new VisibleRowIndex given the new viewport size.
let new_cursor_y = cursor_y as VisibleRowIndex
- (self.lines.len() as VisibleRowIndex - physical_rows as VisibleRowIndex);
self.physical_rows = physical_rows;
self.physical_cols = physical_cols;
CursorPosition {
x: cursor_x,
y: vis_cursor_y,
y: new_cursor_y,
shape: cursor.shape,
visibility: cursor.visibility,
}