diff --git a/docs/changelog.md b/docs/changelog.md index 725f7616c..1de05757c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/mux/src/pane.rs b/mux/src/pane.rs index fe32a28ad..656aad4ea 100644 --- a/mux/src/pane.rs +++ b/mux/src/pane.rs @@ -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 {