diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-02-26 19:54:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-26 19:54:09 +0000 |
commit | ea24a106e943473637c5cadc1a48914a6b8dbd19 (patch) | |
tree | c8657302724a773963fb1caa1dae9ac4b47403d4 | |
parent | 9999bd53e148c692cc16cd74b6ff4a9f143fe22f (diff) | |
download | alacritty-ea24a106e943473637c5cadc1a48914a6b8dbd19.tar.gz alacritty-ea24a106e943473637c5cadc1a48914a6b8dbd19.zip |
Fix vi cursor after leaving search
This resolves an issue which caused the vi cursor position to be
incorrect when leaving the search with the vi cursor at the far bottom.
Previously this could lead to the vi cursor disappearing completely,
when starting a vi mode search that has a match on the last line while
the original vi mode cursor was right above it.
Fixes #4833.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty/src/event.rs | 18 |
2 files changed, 16 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 37eb741f..b6dd2df1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Alacritty failing to start on X11 with invalid DPI reported by XRandr - Text selected after search without any match +- Incorrect vi cursor position after leaving search ### Removed diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index de3be146..bed4d5fe 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -1400,12 +1400,14 @@ impl<N: Notify + OnResize> Processor<N> { { // Compute cursor positions before resize. let num_lines = terminal.screen_lines(); + let vi_mode = terminal.mode().contains(TermMode::VI); let cursor_at_bottom = terminal.grid().cursor.point.line + 1 == num_lines; - let origin_at_bottom = if terminal.mode().contains(TermMode::VI) { + let origin_at_bottom = if vi_mode { terminal.vi_mode_cursor.point.line == num_lines - 1 } else { self.search_state.direction == Direction::Left }; + let old_display_offset = terminal.grid().display_offset(); self.display.handle_update( terminal, @@ -1416,14 +1418,24 @@ impl<N: Notify + OnResize> Processor<N> { display_update_pending, ); - // Scroll to make sure search origin is visible and content moves as little as possible. - if !old_is_searching && self.search_state.history_index.is_some() { + let new_is_searching = self.search_state.history_index.is_some(); + if !old_is_searching && new_is_searching { + // Scroll on search start to make sure origin is visible with minimal viewport motion. let display_offset = terminal.grid().display_offset(); if display_offset == 0 && cursor_at_bottom && !origin_at_bottom { terminal.scroll_display(Scroll::Delta(1)); } else if display_offset != 0 && origin_at_bottom { terminal.scroll_display(Scroll::Delta(-1)); } + } else if old_is_searching + && !new_is_searching + && old_display_offset == 0 + && cursor_at_bottom + && origin_at_bottom + && vi_mode + { + // Pull down the vi cursor if it was moved up when the search was started. + terminal.vi_mode_cursor.point.line += 1; } } |