summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2021-01-03 11:24:04 +0000
committerChristian Duerr <contact@christianduerr.com>2021-01-03 11:49:30 +0000
commit42b41cee94bbd14218718b23db58c96c3cf01cd8 (patch)
treed2cce57f1b833f36eaab234e272fc36772222e99
parenteaabba19d8d664ab06473bd0d4ec43d1244b37aa (diff)
downloadalacritty-42b41cee94bbd14218718b23db58c96c3cf01cd8.tar.gz
alacritty-42b41cee94bbd14218718b23db58c96c3cf01cd8.zip
Fix debug mode crash in vi-less search
-rw-r--r--alacritty/src/event.rs22
-rw-r--r--alacritty/src/input.rs26
-rw-r--r--alacritty_terminal/src/term/search.rs4
3 files changed, 29 insertions, 23 deletions
diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs
index 89063cae..d83469ee 100644
--- a/alacritty/src/event.rs
+++ b/alacritty/src/event.rs
@@ -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.
diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs
index cac21f69..2be0c8c4 100644
--- a/alacritty/src/input.rs
+++ b/alacritty/src/input.rs
@@ -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());
diff --git a/alacritty_terminal/src/term/search.rs b/alacritty_terminal/src/term/search.rs
index 6a31bef0..712daa92 100644
--- a/alacritty_terminal/src/term/search.rs
+++ b/alacritty_terminal/src/term/search.rs
@@ -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;