From e20aa550cbcf7b3f7be6757c007960b3f9b1ac08 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Tue, 13 Mar 2018 22:48:08 +0100 Subject: Fix selection starting in first cell When selecting to the top and starting in the first cell, alacritty would crash. These cases have been fixed and now selection should be completely working. --- src/selection.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/selection.rs b/src/selection.rs index d49236a4..f775f1f6 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -279,8 +279,31 @@ impl Selection { }); } } else if start.line < end.line { - start.col -= 1; end.col += 1; + if start.col > Column(0) { + start.col -= 1; + } + // Special case for when a selection is started + // in the first cell of a line + else { + let ty = match end_side { + Side::Left => SpanType::ExcludeTail, + Side::Right => SpanType::Inclusive, + }; + + // Switch start cell to last cell of previous line + if start_side == Side::Left { + start.line += 1; + start.col = cols - 1; + } + + return Some(Span { + ty, + cols, + front: start, + tail: end, + }); + } } let (front, tail, front_side, tail_side) = if start > end { -- cgit