From ea24a106e943473637c5cadc1a48914a6b8dbd19 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Fri, 26 Feb 2021 19:54:09 +0000 Subject: 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. --- CHANGELOG.md | 1 + 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 Processor { { // 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 Processor { 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; } } -- cgit