Fix Vi cursor not being dirty when scrolling

This commit is contained in:
Kirill Chibisov 2023-11-14 23:17:59 +04:00 committed by GitHub
parent 13834d4de8
commit d83d5af2b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 32 deletions

View File

@ -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

View File

@ -252,6 +252,7 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> 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<T> 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<T> 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.

View File

@ -328,37 +328,33 @@ impl<T: EventListener> Execute<T> 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)),