Fix debug mode crash in vi-less search

This commit is contained in:
Christian Duerr 2021-01-03 11:24:04 +00:00 committed by GitHub
parent c1262d7890
commit 08e111dfae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 23 deletions

View File

@ -429,13 +429,9 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
self.search_state.display_offset_delta = 0;
} else {
match direction {
Direction::Right => {
self.search_state.origin = Point::new(Line(0), num_cols - 1);
self.search_state.display_offset_delta = 1;
},
Direction::Right => self.search_state.origin = Point::new(Line(0), Column(0)),
Direction::Left => {
self.search_state.origin = Point::new(num_lines - 2, Column(0));
self.search_state.display_offset_delta = -1;
self.search_state.origin = Point::new(num_lines - 2, num_cols - 1);
},
}
}
@ -549,8 +545,12 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
// Use focused match as new search origin if available.
if let Some(focused_match) = &self.search_state.focused_match {
let new_origin = match direction {
Direction::Right => *focused_match.end(),
Direction::Left => *focused_match.start(),
Direction::Right => {
focused_match.end().add_absolute(self.terminal, Boundary::Wrap, 1)
},
Direction::Left => {
focused_match.start().sub_absolute(self.terminal, Boundary::Wrap, 1)
},
};
self.terminal.scroll_to_point(new_origin);
@ -575,10 +575,8 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
// Set new origin to the left/right of the match, depending on search direction.
let new_origin = match self.search_state.direction {
Direction::Right => {
focused_match.start().sub_absolute(self.terminal, Boundary::Wrap, 1)
},
Direction::Left => focused_match.end().add_absolute(self.terminal, Boundary::Wrap, 1),
Direction::Right => *focused_match.start(),
Direction::Left => *focused_match.end(),
};
// Store the search origin with display offset by checking how far we need to scroll to it.

View File

@ -24,7 +24,7 @@ use glutin::window::CursorIcon;
use alacritty_terminal::ansi::{ClearMode, Handler};
use alacritty_terminal::event::EventListener;
use alacritty_terminal::grid::{Dimensions, Scroll};
use alacritty_terminal::index::{Column, Direction, Line, Point, Side};
use alacritty_terminal::index::{Boundary, Column, Direction, Line, Point, Side};
use alacritty_terminal::selection::SelectionType;
use alacritty_terminal::term::{ClipboardType, SizeInfo, Term, TermMode};
use alacritty_terminal::vi_mode::ViMotion;
@ -175,26 +175,35 @@ impl<T: EventListener> Execute<T> for Action {
}
},
Action::ViAction(ViAction::SearchNext) => {
let origin = ctx.terminal().visible_to_buffer(ctx.terminal().vi_mode_cursor.point);
let terminal = ctx.terminal();
let origin = terminal
.visible_to_buffer(terminal.vi_mode_cursor.point)
.add_absolute(terminal, Boundary::Wrap, 1);
let direction = ctx.search_direction();
let regex_match = ctx.terminal().search_next(origin, direction, Side::Left, None);
let regex_match = terminal.search_next(origin, direction, Side::Left, None);
if let Some(regex_match) = regex_match {
ctx.terminal_mut().vi_goto_point(*regex_match.start());
}
},
Action::ViAction(ViAction::SearchPrevious) => {
let origin = ctx.terminal().visible_to_buffer(ctx.terminal().vi_mode_cursor.point);
let terminal = ctx.terminal();
let origin = terminal
.visible_to_buffer(terminal.vi_mode_cursor.point)
.sub_absolute(terminal, Boundary::Wrap, 1);
let direction = ctx.search_direction().opposite();
let regex_match = ctx.terminal().search_next(origin, direction, Side::Left, None);
let regex_match = terminal.search_next(origin, direction, Side::Left, None);
if let Some(regex_match) = regex_match {
ctx.terminal_mut().vi_goto_point(*regex_match.start());
}
},
Action::ViAction(ViAction::SearchStart) => {
let terminal = ctx.terminal();
let origin = terminal.visible_to_buffer(ctx.terminal().vi_mode_cursor.point);
let origin = terminal
.visible_to_buffer(terminal.vi_mode_cursor.point)
.sub_absolute(terminal, Boundary::Wrap, 1);
let regex_match = terminal.search_next(origin, Direction::Left, Side::Left, None);
if let Some(regex_match) = regex_match {
ctx.terminal_mut().vi_goto_point(*regex_match.start());
@ -202,7 +211,10 @@ impl<T: EventListener> Execute<T> for Action {
},
Action::ViAction(ViAction::SearchEnd) => {
let terminal = ctx.terminal();
let origin = terminal.visible_to_buffer(ctx.terminal().vi_mode_cursor.point);
let origin = terminal
.visible_to_buffer(terminal.vi_mode_cursor.point)
.add_absolute(terminal, Boundary::Wrap, 1);
let regex_match = terminal.search_next(origin, Direction::Right, Side::Right, None);
if let Some(regex_match) = regex_match {
ctx.terminal_mut().vi_goto_point(*regex_match.end());

View File

@ -87,8 +87,6 @@ impl<T> Term<T> {
side: Side,
max_lines: Option<usize>,
) -> Option<Match> {
// Skip origin itself to exclude it from the search results.
let origin = origin.add_absolute(self, Boundary::Wrap, 1);
let start = self.line_search_left(origin);
let mut end = start;
@ -128,8 +126,6 @@ impl<T> Term<T> {
side: Side,
max_lines: Option<usize>,
) -> Option<Match> {
// Skip origin itself to exclude it from the search results.
let origin = origin.sub_absolute(self, Boundary::Wrap, 1);
let start = self.line_search_right(origin);
let mut end = start;