Fix crash when searching during reset

This fixes a crash which occurs when the terminal is reset while
searching, due to the vi mode cursor being outside of the visible area.

This also fixes an issue where the search state reset would incorrectly
clamp the vi mode cursor to the grid, rather than the absolute viewport
position.

While this fix does resolve all crashes when searching while running
`cat /dev/urandom`, it does raise the question if manually clamping the
vi mode cursor in every location where it is modified is the right
choice.

A follow-up to provide a safer API which guarantees correct modification
of the vi mode cursor location is probably a good idea.

Fixes #5942.
This commit is contained in:
Christian Duerr 2022-03-10 20:45:20 +01:00 committed by GitHub
parent a69c3c408f
commit 0965773657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 2 deletions

View File

@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- Creating the IPC socket failing if WAYLAND_DISPLAY contains an absolute path
- Crash when resetting the terminal while in vi mode
## 0.10.1

View File

@ -853,10 +853,9 @@ impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> {
}
// Reset display offset and cursor position.
self.terminal.vi_mode_cursor.point = self.search_state.origin;
self.terminal.scroll_display(Scroll::Delta(self.search_state.display_offset_delta));
self.search_state.display_offset_delta = 0;
self.terminal.vi_mode_cursor.point =
self.search_state.origin.grid_clamp(self.terminal, Boundary::Grid);
*self.dirty = true;
}

View File

@ -1795,6 +1795,7 @@ impl<T: EventListener> Handler for Term<T> {
self.title_stack = Vec::new();
self.title = None;
self.selection = None;
self.vi_mode_cursor = Default::default();
// Preserve vi mode across resets.
self.mode &= TermMode::VI;