Fix crash when selecting last column

This resolves a bug where the selection start would be set to the number
of columns, causing an out of bounds when trying to index with it.
Instead of extending the selection beyond the grid when the right side
of the last column is the start of the selection, the selection will now
start in the beginning of the next line.

Fixes #3446.
This commit is contained in:
Christian Duerr 2020-03-12 00:14:00 +00:00 committed by GitHub
parent cc2fc0b1c3
commit c2e39085e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -346,6 +346,11 @@ impl Selection {
// Remove first cell if selection starts at the right of a cell
if start.side == Side::Right && start.point != end.point {
start.point.col += 1;
// Wrap to next line when selection starts to the right of last column
if start.point.col == num_cols {
start.point = Point::new(start.point.line.saturating_sub(1), Column(0));
}
}
Some(SelectionRange { start: start.point, end: end.point, is_block: false })