1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-19 03:11:31 +03:00

Ensure that the cursor pos is well defined after resize

This commit is contained in:
Wez Furlong 2018-07-12 21:14:49 -07:00
parent 1361c2ce61
commit e11156abaa

View File

@ -148,7 +148,9 @@ impl Screen {
self.changes.clear();
}
// FIXME: cursor position is now undefined
// Ensure that the cursor position is well-defined
self.xpos = compute_position_change(self.xpos, &Position::NoChange, self.width);
self.ypos = compute_position_change(self.ypos, &Position::NoChange, self.height);
}
pub fn add_change<C: Into<Change>>(&mut self, change: C) -> SequenceNo {
@ -349,7 +351,7 @@ impl Screen {
fn compute_position_change(current: usize, pos: &Position, limit: usize) -> usize {
use self::Position::*;
match pos {
NoChange => current,
NoChange => min(current, limit - 1),
Relative(delta) => {
if *delta > 0 {
min(current.saturating_add(*delta as usize), limit - 1)
@ -527,6 +529,39 @@ mod test {
assert_eq!(full, &*changes);
}
#[test]
fn test_resize_cursor_position() {
let mut s = Screen::new(4, 4);
s.add_change(" a");
s.add_change(Change::CursorPosition {
x: Position::Absolute(3),
y: Position::Absolute(3),
});
assert_eq!(s.xpos, 3);
assert_eq!(s.ypos, 3);
s.resize(2, 2);
assert_eq!(s.xpos, 1);
assert_eq!(s.ypos, 1);
let full = &[
Change::CursorPosition {
x: Position::Absolute(0),
y: Position::Absolute(0),
},
Change::AllAttributes(CellAttributes::default()),
Change::Text(" a ".to_string()),
Change::CursorPosition {
x: Position::Absolute(1),
y: Position::Absolute(1),
},
];
let (_seq, changes) = s.get_changes(0);
assert_eq!(full, &*changes);
}
#[test]
fn test_delta_change() {
let mut s = Screen::new(4, 3);