fix a selection range issue

When dragging a multi-line selection down and to the left, we were
incorrectly setting the computed column range.

Add a test and fix it.
This commit is contained in:
Wez Furlong committed 2018-02-11 18:35:58 -08:00
1 parent 2ee0414b66
commit 5e49a79705
2 files changed
+10 -8

No files matched your search

+7 -8
View File
@@ -61,11 +61,6 @@ impl SelectionRange {
/// more precise than that.
/// Must be called on a normalized range!
pub fn cols_for_row(&self, row: ScrollbackOrVisibleRowIndex) -> Range<usize> {
let (x1, x2) = if self.start.x <= self.end.x {
(self.start.x, self.end.x.saturating_add(1))
} else {
(self.end.x, self.start.x.saturating_add(1))
};
debug_assert!(
self.start.y <= self.end.y,
"you forgot to normalize a SelectionRange"
@@ -74,13 +69,17 @@ impl SelectionRange {
0..0
} else if self.start.y == self.end.y {
// A single line selection
x1..x2
if self.start.x <= self.end.x {
self.start.x..self.end.x.saturating_add(1)
} else {
self.end.x..self.start.x.saturating_add(1)
}
} else if row == self.end.y {
// last line of multi-line
0..x2
0..self.end.x.saturating_add(1)
} else if row == self.start.y {
// first line of multi-line
x1..usize::max_value()
self.start.x..usize::max_value()
} else {
// some "middle" line of multi-line
0..usize::max_value()
+3
View File
@@ -36,6 +36,9 @@ fn drag_selection() {
term.get_clipboard().unwrap(),
"hello world\n\u{1F480}skull\n"
);
term.drag_select(6, 0, 3, 1);
assert_eq!(term.get_clipboard().unwrap(), "world\n\u{1F480}sk");
}
/// Test double click to select a word