Skip to content

Commit 08e111d

Browse files
authored
Fix debug mode crash in vi-less search
1 parent c1262d7 commit 08e111d

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

Diff for: alacritty/src/event.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,9 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
429429
self.search_state.display_offset_delta = 0;
430430
} else {
431431
match direction {
432-
Direction::Right => {
433-
self.search_state.origin = Point::new(Line(0), num_cols - 1);
434-
self.search_state.display_offset_delta = 1;
435-
},
432+
Direction::Right => self.search_state.origin = Point::new(Line(0), Column(0)),
436433
Direction::Left => {
437-
self.search_state.origin = Point::new(num_lines - 2, Column(0));
438-
self.search_state.display_offset_delta = -1;
434+
self.search_state.origin = Point::new(num_lines - 2, num_cols - 1);
439435
},
440436
}
441437
}
@@ -549,8 +545,12 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
549545
// Use focused match as new search origin if available.
550546
if let Some(focused_match) = &self.search_state.focused_match {
551547
let new_origin = match direction {
552-
Direction::Right => *focused_match.end(),
553-
Direction::Left => *focused_match.start(),
548+
Direction::Right => {
549+
focused_match.end().add_absolute(self.terminal, Boundary::Wrap, 1)
550+
},
551+
Direction::Left => {
552+
focused_match.start().sub_absolute(self.terminal, Boundary::Wrap, 1)
553+
},
554554
};
555555

556556
self.terminal.scroll_to_point(new_origin);
@@ -575,10 +575,8 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
575575

576576
// Set new origin to the left/right of the match, depending on search direction.
577577
let new_origin = match self.search_state.direction {
578-
Direction::Right => {
579-
focused_match.start().sub_absolute(self.terminal, Boundary::Wrap, 1)
580-
},
581-
Direction::Left => focused_match.end().add_absolute(self.terminal, Boundary::Wrap, 1),
578+
Direction::Right => *focused_match.start(),
579+
Direction::Left => *focused_match.end(),
582580
};
583581

584582
// Store the search origin with display offset by checking how far we need to scroll to it.

Diff for: alacritty/src/input.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use glutin::window::CursorIcon;
2424
use alacritty_terminal::ansi::{ClearMode, Handler};
2525
use alacritty_terminal::event::EventListener;
2626
use alacritty_terminal::grid::{Dimensions, Scroll};
27-
use alacritty_terminal::index::{Column, Direction, Line, Point, Side};
27+
use alacritty_terminal::index::{Boundary, Column, Direction, Line, Point, Side};
2828
use alacritty_terminal::selection::SelectionType;
2929
use alacritty_terminal::term::{ClipboardType, SizeInfo, Term, TermMode};
3030
use alacritty_terminal::vi_mode::ViMotion;
@@ -175,34 +175,46 @@ impl<T: EventListener> Execute<T> for Action {
175175
}
176176
},
177177
Action::ViAction(ViAction::SearchNext) => {
178-
let origin = ctx.terminal().visible_to_buffer(ctx.terminal().vi_mode_cursor.point);
178+
let terminal = ctx.terminal();
179+
let origin = terminal
180+
.visible_to_buffer(terminal.vi_mode_cursor.point)
181+
.add_absolute(terminal, Boundary::Wrap, 1);
179182
let direction = ctx.search_direction();
180183

181-
let regex_match = ctx.terminal().search_next(origin, direction, Side::Left, None);
184+
let regex_match = terminal.search_next(origin, direction, Side::Left, None);
182185
if let Some(regex_match) = regex_match {
183186
ctx.terminal_mut().vi_goto_point(*regex_match.start());
184187
}
185188
},
186189
Action::ViAction(ViAction::SearchPrevious) => {
187-
let origin = ctx.terminal().visible_to_buffer(ctx.terminal().vi_mode_cursor.point);
190+
let terminal = ctx.terminal();
191+
let origin = terminal
192+
.visible_to_buffer(terminal.vi_mode_cursor.point)
193+
.sub_absolute(terminal, Boundary::Wrap, 1);
188194
let direction = ctx.search_direction().opposite();
189195

190-
let regex_match = ctx.terminal().search_next(origin, direction, Side::Left, None);
196+
let regex_match = terminal.search_next(origin, direction, Side::Left, None);
191197
if let Some(regex_match) = regex_match {
192198
ctx.terminal_mut().vi_goto_point(*regex_match.start());
193199
}
194200
},
195201
Action::ViAction(ViAction::SearchStart) => {
196202
let terminal = ctx.terminal();
197-
let origin = terminal.visible_to_buffer(ctx.terminal().vi_mode_cursor.point);
203+
let origin = terminal
204+
.visible_to_buffer(terminal.vi_mode_cursor.point)
205+
.sub_absolute(terminal, Boundary::Wrap, 1);
206+
198207
let regex_match = terminal.search_next(origin, Direction::Left, Side::Left, None);
199208
if let Some(regex_match) = regex_match {
200209
ctx.terminal_mut().vi_goto_point(*regex_match.start());
201210
}
202211
},
203212
Action::ViAction(ViAction::SearchEnd) => {
204213
let terminal = ctx.terminal();
205-
let origin = terminal.visible_to_buffer(ctx.terminal().vi_mode_cursor.point);
214+
let origin = terminal
215+
.visible_to_buffer(terminal.vi_mode_cursor.point)
216+
.add_absolute(terminal, Boundary::Wrap, 1);
217+
206218
let regex_match = terminal.search_next(origin, Direction::Right, Side::Right, None);
207219
if let Some(regex_match) = regex_match {
208220
ctx.terminal_mut().vi_goto_point(*regex_match.end());

Diff for: alacritty_terminal/src/term/search.rs

-4
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ impl<T> Term<T> {
8787
side: Side,
8888
max_lines: Option<usize>,
8989
) -> Option<Match> {
90-
// Skip origin itself to exclude it from the search results.
91-
let origin = origin.add_absolute(self, Boundary::Wrap, 1);
9290
let start = self.line_search_left(origin);
9391
let mut end = start;
9492

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

0 commit comments

Comments
 (0)