diff options
author | jeremycostanzo <56163564+jeremycostanzo@users.noreply.github.com> | 2022-06-09 23:08:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-10 00:08:18 +0300 |
commit | fdcf99b0c17214d2318298bc4ea911931c3b9ece (patch) | |
tree | 85acf79129bf9c3e2eaafacd2d4596a9fee4983d /alacritty/src | |
parent | 90552e3e7f8f085919a39435a8a68b3a2f633e54 (diff) | |
download | r-alacritty-fdcf99b0c17214d2318298bc4ea911931c3b9ece.tar.gz r-alacritty-fdcf99b0c17214d2318298bc4ea911931c3b9ece.tar.bz2 r-alacritty-fdcf99b0c17214d2318298bc4ea911931c3b9ece.zip |
Add vi action to center view around vi cursor
Diffstat (limited to 'alacritty/src')
-rw-r--r-- | alacritty/src/config/bindings.rs | 4 | ||||
-rw-r--r-- | alacritty/src/input.rs | 9 |
2 files changed, 13 insertions, 0 deletions
diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index 4c706811..c48b2d75 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -275,6 +275,8 @@ pub enum ViAction { SearchEnd, /// Launch the URL below the vi mode cursor. Open, + /// Centers the screen around the vi mode cursor. + CenterAroundViCursor, } /// Search mode specific actions. @@ -498,6 +500,8 @@ pub fn default_key_bindings() -> Vec<KeyBinding> { ViAction::SearchPrevious; Return, +BindingMode::VI, ~BindingMode::SEARCH; ViAction::Open; + Z, +BindingMode::VI, ~BindingMode::SEARCH; + ViAction::CenterAroundViCursor; K, +BindingMode::VI, ~BindingMode::SEARCH; ViMotion::Up; J, +BindingMode::VI, ~BindingMode::SEARCH; diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 0f389851..0441ecb4 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -230,6 +230,15 @@ impl<T: EventListener> Execute<T> for Action { ctx.mark_dirty(); } }, + Action::Vi(ViAction::CenterAroundViCursor) => { + let term = ctx.terminal(); + let display_offset = term.grid().display_offset() as i32; + let target = -display_offset + term.screen_lines() as i32 / 2 - 1; + let line = term.vi_mode_cursor.point.line; + let scroll_lines = target - line.0; + + ctx.scroll(Scroll::Delta(scroll_lines)); + }, Action::Search(SearchAction::SearchFocusNext) => { ctx.advance_search_origin(ctx.search_direction()); }, |