rectangular selection: fix selection
fixes: * beginning the selection with the top right or bottom left corner * beginning the selection with the bottom right corner and only select a single line
This commit is contained in:
1 parent
9600d52cd8
commit
4b302e8f57
2 files changed
+52
-33
No files matched your search
@@ -219,30 +219,37 @@ impl SelectionRange {
|
||||
/// Must be called on a normalized range!
|
||||
pub fn cols_for_row(&self, row: StableRowIndex, rectangular: bool) -> Range<usize> {
|
||||
let norm = self.normalize();
|
||||
let range = if row < norm.start.y || row > norm.end.y {
|
||||
0..0
|
||||
} else if norm.start.y == norm.end.y {
|
||||
// A single line selection
|
||||
if norm.start.x <= norm.end.x {
|
||||
norm.start.x..norm.end.x.saturating_add(1)
|
||||
} else {
|
||||
norm.end.x..norm.start.x.saturating_add(1)
|
||||
}
|
||||
} else if row == norm.end.y {
|
||||
// last line of multi-line
|
||||
0..norm.end.x.saturating_add(1)
|
||||
} else if row == norm.start.y {
|
||||
// first line of multi-line
|
||||
norm.start.x..usize::max_value()
|
||||
} else {
|
||||
// some "middle" line of multi-line
|
||||
0..usize::max_value()
|
||||
};
|
||||
|
||||
if rectangular {
|
||||
range.start.max(norm.start.x)..range.end.min(norm.end.x.saturating_add(1))
|
||||
if row < norm.start.y || row > norm.end.y {
|
||||
0..0
|
||||
} else {
|
||||
if norm.start.x <= norm.end.x {
|
||||
norm.start.x..norm.end.x.saturating_add(1)
|
||||
} else {
|
||||
norm.end.x..norm.start.x.saturating_add(1)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
range
|
||||
if row < norm.start.y || row > norm.end.y {
|
||||
0..0
|
||||
} else if norm.start.y == norm.end.y {
|
||||
// A single line selection
|
||||
if norm.start.x <= norm.end.x {
|
||||
norm.start.x..norm.end.x.saturating_add(1)
|
||||
} else {
|
||||
norm.end.x..norm.start.x.saturating_add(1)
|
||||
}
|
||||
} else if row == norm.end.y {
|
||||
// last line of multi-line
|
||||
0..norm.end.x.saturating_add(1)
|
||||
} else if row == norm.start.y {
|
||||
// first line of multi-line
|
||||
norm.start.x..usize::max_value()
|
||||
} else {
|
||||
// some "middle" line of multi-line
|
||||
0..usize::max_value()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,19 +90,31 @@ impl super::TermWindow {
|
||||
// Compute the start and end horizontall cell of the selection.
|
||||
// The selection extent depends on the mouse cursor position in relation
|
||||
// to the origin.
|
||||
let (start_x, end_x) = if (x >= origin.x && y == origin.y) || y > origin.y {
|
||||
// If the selection is extending forwards from the origin, it includes the
|
||||
// origin and doesn't include the cell under the cursor. Note that the
|
||||
// reported cell here is offset by -50% from the real cell you see on the
|
||||
// screen, so this causes a visual cell on the screen to be selected when
|
||||
// the mouse moves over 50% of its width, which effectively means the next
|
||||
// cell is being reported here, hence it's excluded
|
||||
(origin.x, x.saturating_sub(1))
|
||||
let (start_x, end_x) = if mode == SelectionMode::Block {
|
||||
if x >= origin.x {
|
||||
// If the selection is extending forwards from the origin,
|
||||
// it includes the origin
|
||||
(origin.x, x.saturating_sub(1))
|
||||
} else {
|
||||
// If the selection is extending backwards from the origin,
|
||||
// it doesn't include the origin
|
||||
(origin.x.saturating_sub(1), x)
|
||||
}
|
||||
} else {
|
||||
// If the selection is extending backwards from the origin, it doesn't
|
||||
// include the origin and includes the cell under the cursor, which has
|
||||
// the same effect as described above when going backwards
|
||||
(origin.x.saturating_sub(1), x)
|
||||
if (x >= origin.x && y == origin.y) || y > origin.y {
|
||||
// If the selection is extending forwards from the origin, it includes the
|
||||
// origin and doesn't include the cell under the cursor. Note that the
|
||||
// reported cell here is offset by -50% from the real cell you see on the
|
||||
// screen, so this causes a visual cell on the screen to be selected when
|
||||
// the mouse moves over 50% of its width, which effectively means the next
|
||||
// cell is being reported here, hence it's excluded
|
||||
(origin.x, x.saturating_sub(1))
|
||||
} else {
|
||||
// If the selection is extending backwards from the origin, it doesn't
|
||||
// include the origin and includes the cell under the cursor, which has
|
||||
// the same effect as described above when going backwards
|
||||
(origin.x.saturating_sub(1), x)
|
||||
}
|
||||
};
|
||||
|
||||
self.selection(pane.pane_id()).range = if origin.x != x || origin.y != y {
|
||||
|
||||
Reference in new issue
Block a user