fix a possible panic when word-selecting off the top of viewport

refs: https://github.com/wez/wezterm/issues/713
This commit is contained in:
Wez Furlong committed 2021-04-23 19:10:26 -07:00
1 parent ff7f097fb9
commit d6cfa9c610
2 files changed
+12 -7

No files matched your search

+1
View File
@@ -31,6 +31,7 @@ As features stabilize some brief notes about them will accumulate here.
* Improved: font-config queries now run much faster, resulting in snappier startup on unix systems
* Fixed: [Hide](config/lua/keyassignment/Hide.md) had no effect on macOS when the titlebar was disabled [#679](https://github.com/wez/wezterm/issues/679)
* Fixed: key and mouse assignments set via [window:set_config_overrides](config/lua/window/set_config_overrides.md) were not respected. [#656](https://github.com/wez/wezterm/issues/656)
* Fixed: potential panic when word selecting off top of viewport [#713](https://github.com/wez/wezterm/issues/713)
### 20210405-110924-a5bb5be8
+11 -7
View File
@@ -86,18 +86,19 @@ impl LogicalLine {
let mut offset = 0;
for (idx, line) in self.physical_lines.iter().enumerate() {
let phys_y = self.first_row + idx as StableRowIndex;
if y < phys_y {
// Eg: trying to drag off the top of the viewport.
// Their y coordinate precedes our first line, so
// the only logical x we can return is 0
return 0;
}
if phys_y == y {
return offset + x;
}
offset += line.cells().len();
}
panic!(
"x={} y={} is outside of this logical line starting at {} comprised of {} physical lines",
x, y,
self.first_row,
self.physical_lines.len()
);
// Allow selecting off the end of the line
offset + x
}
pub fn logical_x_to_physical_coord(&self, x: usize) -> (StableRowIndex, usize) {
@@ -815,6 +816,9 @@ mod test {
first_row: 0,
};
assert_eq!(logical.xy_to_logical_x(2, -1), 0);
assert_eq!(logical.xy_to_logical_x(20, 1), 25);
let start_idx = logical.xy_to_logical_x(2, 1);
fn is_double_click_word(s: &str) -> bool {