aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/selection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_terminal/src/selection.rs')
-rw-r--r--alacritty_terminal/src/selection.rs108
1 files changed, 54 insertions, 54 deletions
diff --git a/alacritty_terminal/src/selection.rs b/alacritty_terminal/src/selection.rs
index 29934e5a..5f94634f 100644
--- a/alacritty_terminal/src/selection.rs
+++ b/alacritty_terminal/src/selection.rs
@@ -144,22 +144,22 @@ impl Selection {
// Simple selection is empty when the points are identical
// or two adjacent cells have the sides right -> left
start == end
- || (start.side == Side::Left
- && end.side == Side::Right
+ || (start.side == Side::Right
+ && end.side == Side::Left
&& (start.point.line == end.point.line)
- && start.point.col == end.point.col + 1)
+ && start.point.col + 1 == end.point.col)
},
Selection::Block { region: Range { ref start, ref end } } => {
// Block selection is empty when the points' columns and sides are identical
// or two cells with adjacent columns have the sides right -> left,
// regardless of their lines
(start.point.col == end.point.col && start.side == end.side)
- || (start.point.col == end.point.col + 1
+ || (start.point.col + 1 == end.point.col
+ && start.side == Side::Right
+ && end.side == Side::Left)
+ || (end.point.col + 1 == start.point.col
&& start.side == Side::Left
&& end.side == Side::Right)
- || (end.point.col == start.point.col + 1
- && end.side == Side::Left
- && start.side == Side::Right)
},
Selection::Semantic { .. } | Selection::Lines { .. } => false,
}
@@ -214,16 +214,16 @@ impl Selection {
span.map(|mut span| {
let grid = term.grid();
- if span.end.col < cols
- && grid[span.end.line][span.end.col].flags.contains(Flags::WIDE_CHAR_SPACER)
+ if span.start.col < cols
+ && grid[span.start.line][span.start.col].flags.contains(Flags::WIDE_CHAR_SPACER)
{
- span.end.col = Column(span.end.col.saturating_sub(1));
+ span.start.col = Column(span.start.col.saturating_sub(1));
}
- if span.start.col.0 < cols.saturating_sub(1)
- && grid[span.start.line][span.start.col].flags.contains(Flags::WIDE_CHAR)
+ if span.end.col.0 < cols.saturating_sub(1)
+ && grid[span.end.line][span.end.col].flags.contains(Flags::WIDE_CHAR)
{
- span.start.col += 1;
+ span.end.col += 1;
}
span
@@ -232,7 +232,7 @@ impl Selection {
// Bring start and end points in the correct order
fn points_need_swap(start: Point<isize>, end: Point<isize>) -> bool {
- start.line > end.line || start.line == end.line && start.col < end.col
+ start.line < end.line || start.line == end.line && start.col > end.col
}
// Clamp selection inside the grid to prevent out of bounds errors
@@ -242,26 +242,26 @@ impl Selection {
lines: isize,
cols: Column,
) -> Option<(Point<isize>, Point<isize>)> {
- if end.line >= lines {
+ if start.line >= lines {
// Don't show selection above visible region
- if start.line >= lines {
+ if end.line >= lines {
return None;
}
// Clamp selection above viewport to visible region
- end.line = lines - 1;
- end.col = Column(0);
+ start.line = lines - 1;
+ start.col = Column(0);
}
- if start.line < 0 {
+ if end.line < 0 {
// Don't show selection below visible region
- if end.line < 0 {
+ if start.line < 0 {
return None;
}
// Clamp selection below viewport to visible region
- start.line = 0;
- start.col = cols - 1;
+ end.line = 0;
+ end.col = cols - 1;
}
Some((start, end))
@@ -275,10 +275,10 @@ impl Selection {
if let Some(end) = term.bracket_search(start.into()) {
(start.into(), end)
} else {
- (term.semantic_search_right(start.into()), term.semantic_search_left(end.into()))
+ (term.semantic_search_left(start.into()), term.semantic_search_right(end.into()))
}
} else {
- (term.semantic_search_right(start.into()), term.semantic_search_left(end.into()))
+ (term.semantic_search_left(start.into()), term.semantic_search_right(end.into()))
};
Some(Span { start, end, is_block: false })
@@ -288,8 +288,8 @@ impl Selection {
where
T: Dimensions,
{
- start.col = term.dimensions().col - 1;
- end.col = Column(0);
+ end.col = term.dimensions().col - 1;
+ start.col = Column(0);
Some(Span { start: start.into(), end: end.into(), is_block: false })
}
@@ -310,19 +310,19 @@ impl Selection {
}
// Remove last cell if selection ends to the left of a cell
- if start_side == Side::Left && start != end {
- // Special case when selection starts to left of first cell
- if start.col == Column(0) {
- start.col = term.dimensions().col - 1;
- start.line += 1;
+ if end_side == Side::Left && start != end {
+ // Special case when selection ends to left of first cell
+ if end.col == Column(0) {
+ end.col = term.dimensions().col - 1;
+ end.line += 1;
} else {
- start.col -= 1;
+ end.col -= 1;
}
}
// Remove first cell if selection starts at the right of a cell
- if end_side == Side::Right && start != end {
- end.col += 1;
+ if start_side == Side::Right && start != end {
+ start.col += 1;
}
// Return the selection with all cells inclusive
@@ -340,20 +340,20 @@ impl Selection {
return None;
}
- // Always go bottom-right -> top-left
- if start.col < end.col {
+ // Always go top-left -> bottom-right
+ if start.col > end.col {
std::mem::swap(&mut start_side, &mut end_side);
std::mem::swap(&mut start.col, &mut end.col);
}
// Remove last cell if selection ends to the left of a cell
- if start_side == Side::Left && start != end && start.col.0 > 0 {
- start.col -= 1;
+ if end_side == Side::Left && start != end && end.col.0 > 0 {
+ end.col -= 1;
}
// Remove first cell if selection starts at the right of a cell
- if end_side == Side::Right && start != end {
- end.col += 1;
+ if start_side == Side::Right && start != end {
+ start.col += 1;
}
// Return the selection with all cells inclusive
@@ -508,8 +508,8 @@ mod test {
selection.update(Point::new(0, Column(1)), Side::Right);
assert_eq!(selection.to_span(&term(5, 2)).unwrap(), Span {
- start: Point::new(0, Column(1)),
- end: Point::new(1, Column(2)),
+ start: Point::new(1, Column(2)),
+ end: Point::new(0, Column(1)),
is_block: false,
});
}
@@ -532,8 +532,8 @@ mod test {
selection.update(Point::new(1, Column(0)), Side::Right);
assert_eq!(selection.to_span(&term(5, 2)).unwrap(), Span {
- start: Point::new(0, Column(1)),
- end: Point::new(1, Column(1)),
+ start: Point::new(1, Column(1)),
+ end: Point::new(0, Column(1)),
is_block: false,
});
}
@@ -545,8 +545,8 @@ mod test {
selection.rotate(-3);
assert_eq!(selection.to_span(&term(5, 10)).unwrap(), Span {
- start: Point::new(0, Column(4)),
- end: Point::new(2, Column(0)),
+ start: Point::new(2, Column(0)),
+ end: Point::new(0, Column(4)),
is_block: false,
});
}
@@ -558,8 +558,8 @@ mod test {
selection.rotate(-3);
assert_eq!(selection.to_span(&term(5, 10)).unwrap(), Span {
- start: Point::new(0, Column(4)),
- end: Point::new(2, Column(3)),
+ start: Point::new(2, Column(3)),
+ end: Point::new(0, Column(4)),
is_block: false,
});
}
@@ -571,8 +571,8 @@ mod test {
selection.rotate(-3);
assert_eq!(selection.to_span(&term(5, 10)).unwrap(), Span {
- start: Point::new(0, Column(4)),
- end: Point::new(2, Column(4)),
+ start: Point::new(2, Column(4)),
+ end: Point::new(0, Column(4)),
is_block: false,
});
}
@@ -584,8 +584,8 @@ mod test {
selection.rotate(-3);
assert_eq!(selection.to_span(&term(5, 10)).unwrap(), Span {
- start: Point::new(0, Column(4)),
- end: Point::new(2, Column(4)),
+ start: Point::new(2, Column(4)),
+ end: Point::new(0, Column(4)),
is_block: true,
});
}
@@ -604,8 +604,8 @@ mod test {
selection.update(Point::new(0, Column(8)), Side::Right);
assert_eq!(selection.to_span(&term).unwrap(), Span {
- start: Point::new(0, Column(9)),
- end: Point::new(0, Column(0)),
+ start: Point::new(0, Column(0)),
+ end: Point::new(0, Column(9)),
is_block: false,
});
}