diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-07-14 15:17:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-14 15:17:29 +0000 |
commit | 183622e9433c25676b2f3a9d8314f1e19089a26c (patch) | |
tree | e02abce89f47c1c30d102ee0b1b441c7388030be | |
parent | 76a4c373da48a4477c07b844442e5599fbd37ada (diff) | |
download | alacritty-183622e9433c25676b2f3a9d8314f1e19089a26c.tar.gz alacritty-183622e9433c25676b2f3a9d8314f1e19089a26c.zip |
Fix movement within search matches
Previously the SearchEndNext and SearchEndPrevious match acted exactly
like the SearchNext and SearchPrevious action, however this is not how
vim works. In vim, regardless of direction the `gN` action always jumps
to the next match start to the left of the cursor, while the `gn` action
always jumps to the next search end to the right of the cursor.
While both approaches might seem reasonable at first, vim's approach has
a significant advantage w.r.t. predictability and automation of the
movement. By always knowing which direction the motion goes to, this
allows for mappings that reliably navigate inside the current match
regardless of the global search direction. So deleting until the end of
the match would always be `dgn` for example, regardless in which
direction the user has jumped to it.
Fixes #3953.
-rw-r--r-- | alacritty.yml | 4 | ||||
-rw-r--r-- | alacritty/src/config/bindings.rs | 8 | ||||
-rw-r--r-- | alacritty/src/input.rs | 20 |
3 files changed, 15 insertions, 17 deletions
diff --git a/alacritty.yml b/alacritty.yml index 5a14a417..63d8f6c7 100644 --- a/alacritty.yml +++ b/alacritty.yml @@ -534,8 +534,8 @@ # - ToggleSemanticSelection # - SearchNext # - SearchPrevious -# - SearchEndNext -# - SearchEndPrevious +# - SearchStart +# - SearchEnd # # (macOS only): # - ToggleSimpleFullscreen: Enters fullscreen without occupying another space diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index 81a46d66..77521318 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -218,10 +218,10 @@ pub enum ViAction { SearchNext, /// Jump to the beginning of the previous match. SearchPrevious, - /// Jump to the end of the next match. - SearchEndNext, - /// Jump to the end of the previous match. - SearchEndPrevious, + /// Jump to the next start of a match to the left of the origin. + SearchStart, + /// Jump to the next end of a match to the right of the origin. + SearchEnd, /// Launch the URL below the vi mode cursor. Open, } diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 2d865990..58ca42cb 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -208,20 +208,18 @@ impl<T: EventListener> Execute<T> for Action { ctx.terminal_mut().vi_goto_point(*regex_match.start()); } }, - Action::ViAction(ViAction::SearchEndNext) => { - let origin = ctx.terminal().visible_to_buffer(ctx.terminal().vi_mode_cursor.point); - let direction = ctx.search_direction(); - - let regex_match = ctx.terminal().search_next(origin, direction, Side::Right, None); + Action::ViAction(ViAction::SearchStart) => { + let terminal = ctx.terminal(); + let origin = terminal.visible_to_buffer(ctx.terminal().vi_mode_cursor.point); + 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.end()); + ctx.terminal_mut().vi_goto_point(*regex_match.start()); } }, - Action::ViAction(ViAction::SearchEndPrevious) => { - let origin = ctx.terminal().visible_to_buffer(ctx.terminal().vi_mode_cursor.point); - let direction = ctx.search_direction().opposite(); - - let regex_match = ctx.terminal().search_next(origin, direction, Side::Right, None); + Action::ViAction(ViAction::SearchEnd) => { + let terminal = ctx.terminal(); + let origin = terminal.visible_to_buffer(ctx.terminal().vi_mode_cursor.point); + 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()); } |