mirror of
https://github.com/wez/wezterm.git
synced 2024-12-20 20:01:38 +03:00
Ensure that the cursor pos is well defined after resize
This commit is contained in:
parent
1361c2ce61
commit
e11156abaa
@ -148,7 +148,9 @@ impl Screen {
|
|||||||
self.changes.clear();
|
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 {
|
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 {
|
fn compute_position_change(current: usize, pos: &Position, limit: usize) -> usize {
|
||||||
use self::Position::*;
|
use self::Position::*;
|
||||||
match pos {
|
match pos {
|
||||||
NoChange => current,
|
NoChange => min(current, limit - 1),
|
||||||
Relative(delta) => {
|
Relative(delta) => {
|
||||||
if *delta > 0 {
|
if *delta > 0 {
|
||||||
min(current.saturating_add(*delta as usize), limit - 1)
|
min(current.saturating_add(*delta as usize), limit - 1)
|
||||||
@ -527,6 +529,39 @@ mod test {
|
|||||||
assert_eq!(full, &*changes);
|
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]
|
#[test]
|
||||||
fn test_delta_change() {
|
fn test_delta_change() {
|
||||||
let mut s = Screen::new(4, 3);
|
let mut s = Screen::new(4, 3);
|
||||||
|
Loading…
Reference in New Issue
Block a user