Merge pull request #70 from RLHerbert/master

Fix panic when buffer larger than terminal width
This commit is contained in:
Blaž Hrastnik 2021-06-03 10:28:14 +09:00 committed by GitHub
commit 3c7729906c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -143,8 +143,9 @@ pub fn screen_coords_at_pos(
} }
} }
let row = line - self.first_line as usize; // It is possible for underflow to occur if the buffer length is larger than the terminal width.
let col = col - self.first_col as usize; let row = line.saturating_sub(self.first_line);
let col = col.saturating_sub(self.first_col);
Some(Position::new(row, col)) Some(Position::new(row, col))
} }