Skip to content

Commit

Permalink
Fix crash when searching during reset
Browse files Browse the repository at this point in the history
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 alacritty#5942.
  • Loading branch information
chrisduerr authored Mar 10, 2022
1 parent a69c3c4 commit 0965773
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions alacritty/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions alacritty_terminal/src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0965773

Please sign in to comment.