termwiz: fix bounds checking in Line::compute_double_click_range
closes: https://github.com/wez/wezterm/issues/283
This commit is contained in:
1 parent
f4dc7a2a3a
commit
3aed1b1327
1 file changed
+10
-1
@@ -32,6 +32,7 @@ pub struct Line {
|
||||
cells: Vec<Cell>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum DoubleClickRange {
|
||||
Range(Range<usize>),
|
||||
RangeWithWrap(Range<usize>),
|
||||
@@ -259,7 +260,8 @@ impl Line {
|
||||
lower = idx;
|
||||
}
|
||||
|
||||
if upper > lower && self.cells[upper - 1].attrs().wrapped() {
|
||||
let len = self.cells.len();
|
||||
if upper > lower && self.cells[upper.min(len) - 1].attrs().wrapped() {
|
||||
DoubleClickRange::RangeWithWrap(lower..upper)
|
||||
} else {
|
||||
DoubleClickRange::Range(lower..upper)
|
||||
@@ -618,4 +620,11 @@ mod test {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_click_range_bounds() {
|
||||
let line: Line = "hello".into();
|
||||
let r = line.compute_double_click_range(200, |_| true);
|
||||
assert_eq!(r, DoubleClickRange::Range(0..200));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user