From d83d5af2b571e5dc2c5c622277096a91c04ca7eb Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Tue, 14 Nov 2023 23:17:59 +0400 Subject: [PATCH] Fix Vi cursor not being dirty when scrolling --- CHANGELOG.md | 1 + alacritty/src/event.rs | 17 +++++++++----- alacritty/src/input.rs | 50 +++++++++++++++++++----------------------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48a65132..7546f001 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Crash when leaving search after resize - Cursor being hidden after reaching cursor blinking timeout - Message bar content getting stuck after closing with multiple messages on Wayland +- Vi cursor position not redrawn on PageUp/PageDown without scrollback ### Removed diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index f7fd044c..e6f77e8c 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -252,6 +252,7 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext for ActionCon fn scroll(&mut self, scroll: Scroll) { let old_offset = self.terminal.grid().display_offset() as i32; + let old_vi_cursor = self.terminal.vi_mode_cursor; self.terminal.scroll_display(scroll); let lines_changed = old_offset - self.terminal.grid().display_offset() as i32; @@ -261,10 +262,10 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext for ActionCon self.search_state.display_offset_delta += lines_changed; } + let vi_mode = self.terminal.mode().contains(TermMode::VI); + // Update selection. - if self.terminal.mode().contains(TermMode::VI) - && self.terminal.selection.as_ref().map_or(false, |s| !s.is_empty()) - { + if vi_mode && self.terminal.selection.as_ref().map_or(false, |s| !s.is_empty()) { self.update_selection(self.terminal.vi_mode_cursor.point, Side::Right); } else if self.mouse.left_button_state == ElementState::Pressed || self.mouse.right_button_state == ElementState::Pressed @@ -274,8 +275,14 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext for ActionCon self.update_selection(point, self.mouse.cell_side); } - // Update dirty if actually scrolled or we're in the Vi mode. - *self.dirty |= lines_changed != 0; + // Scrolling inside Vi mode moves the cursor, so start typing. + if vi_mode { + self.on_typing_start(); + } + + // Update dirty if actually scrolled or moved Vi cursor in Vi mode. + *self.dirty |= + lines_changed != 0 || (vi_mode && old_vi_cursor != self.terminal.vi_mode_cursor); } // Copy text selection. diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 3c11c435..2c853488 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -328,37 +328,33 @@ impl Execute for Action { Action::IncreaseFontSize => ctx.change_font_size(FONT_SIZE_STEP), Action::DecreaseFontSize => ctx.change_font_size(FONT_SIZE_STEP * -1.), Action::ResetFontSize => ctx.reset_font_size(), - Action::ScrollPageUp => { + Action::ScrollPageUp + | Action::ScrollPageDown + | Action::ScrollHalfPageUp + | Action::ScrollHalfPageDown => { // Move vi mode cursor. let term = ctx.terminal_mut(); - let scroll_lines = term.screen_lines() as i32; - term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines); + let (scroll, amount) = match self { + Action::ScrollPageUp => (Scroll::PageUp, term.screen_lines() as i32), + Action::ScrollPageDown => (Scroll::PageDown, -(term.screen_lines() as i32)), + Action::ScrollHalfPageUp => { + let amount = term.screen_lines() as i32 / 2; + (Scroll::Delta(amount), amount) + }, + Action::ScrollHalfPageDown => { + let amount = -(term.screen_lines() as i32 / 2); + (Scroll::Delta(amount), amount) + }, + _ => unreachable!(), + }; - ctx.scroll(Scroll::PageUp); - }, - Action::ScrollPageDown => { - // Move vi mode cursor. - let term = ctx.terminal_mut(); - let scroll_lines = -(term.screen_lines() as i32); - term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines); + let old_vi_cursor = term.vi_mode_cursor; + term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, amount); + if old_vi_cursor != term.vi_mode_cursor { + ctx.mark_dirty(); + } - ctx.scroll(Scroll::PageDown); - }, - Action::ScrollHalfPageUp => { - // Move vi mode cursor. - let term = ctx.terminal_mut(); - let scroll_lines = term.screen_lines() as i32 / 2; - term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines); - - ctx.scroll(Scroll::Delta(scroll_lines)); - }, - Action::ScrollHalfPageDown => { - // Move vi mode cursor. - let term = ctx.terminal_mut(); - let scroll_lines = -(term.screen_lines() as i32 / 2); - term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines); - - ctx.scroll(Scroll::Delta(scroll_lines)); + ctx.scroll(scroll); }, Action::ScrollLineUp => ctx.scroll(Scroll::Delta(1)), Action::ScrollLineDown => ctx.scroll(Scroll::Delta(-1)),