Add basic vi motion support for terminal (#18715)

Closes #7417

Release Notes:

- Added basic support for Alacritty's [vi
mode](https://github.com/alacritty/alacritty/blob/master/docs/features.md#vi-mode)
to the built-in terminal (which is using Alacritty under the hood.) The
vi mode can be activated with `ctrl-shift-space` and then supports some
basic motions to navigate through the terminal's scrollback buffer.

## Details

Leverages existing selection functionality from mouse_drag and the
ViMotion API of alacritty to add basic vi motions in the terminal.
Please note, this is only basic functionality (move, select, and yank to
system clipboard) and not a fully functional vim environment (e.g.
search, configurable keybindings, and paste). I figured this would be an
interim solution to the long term, more fleshed out, solution proposed
by @mrnugget.

Ctrl+Shift+Space to enter Vi mode while in the terminal (Same default
binding in alacritty)
This commit is contained in:
Cody 2024-10-10 01:50:12 -04:00 committed by GitHub
parent 5cf4ac16d6
commit fe1078ef68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 164 additions and 3 deletions

View file

@ -22,7 +22,7 @@ use terminal::{
terminal_settings::{CursorShape, TerminalBlink, TerminalSettings, WorkingDirectory},
Clear, Copy, Event, MaybeNavigationTarget, Paste, ScrollLineDown, ScrollLineUp, ScrollPageDown,
ScrollPageUp, ScrollToBottom, ScrollToTop, ShowCharacterPalette, TaskStatus, Terminal,
TerminalSize,
TerminalSize, ToggleViMode,
};
use terminal_element::{is_blank, TerminalElement};
use terminal_panel::TerminalPanel;
@ -431,6 +431,11 @@ impl TerminalView {
cx.notify();
}
fn toggle_vi_mode(&mut self, _: &ToggleViMode, cx: &mut ViewContext<Self>) {
self.terminal.update(cx, |term, _| term.toggle_vi_mode());
cx.notify();
}
pub fn should_show_cursor(&self, focused: bool, cx: &mut gpui::ViewContext<Self>) -> bool {
//Don't blink the cursor when not focused, blinking is disabled, or paused
if !focused
@ -968,6 +973,7 @@ impl Render for TerminalView {
.on_action(cx.listener(TerminalView::scroll_page_down))
.on_action(cx.listener(TerminalView::scroll_to_top))
.on_action(cx.listener(TerminalView::scroll_to_bottom))
.on_action(cx.listener(TerminalView::toggle_vi_mode))
.on_action(cx.listener(TerminalView::show_character_palette))
.on_action(cx.listener(TerminalView::select_all))
.on_key_down(cx.listener(Self::key_down))