From 0a49ccbebfcb6c19c51ca60fb95c3e2214b30873 Mon Sep 17 00:00:00 2001 From: iyht Date: Wed, 26 Mar 2025 08:23:23 -0700 Subject: [PATCH] Allow the keybinding context to detect the terminal vi_mode (#26236) Release Notes: - Added support for detecting the vi_mode in the keybinding context. Now we can define and use the keybinding when the terminal is in vi_mode. https://github.com/user-attachments/assets/a927b6c9-c634-4739-9502-8457614d9a90 --- crates/terminal/src/terminal.rs | 4 ++++ crates/terminal_view/src/terminal_view.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 354044706b2af424880fa48b023ef7f4ee80de11..99aa5ca4df229e5efae14c658ebabee6d5447f74 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -1911,6 +1911,10 @@ impl Terminal { } } } + + pub fn vi_mode_enabled(&self) -> bool { + self.vi_mode_enabled + } } // Helper function to convert a grid row to a string diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 66635b12f5faf18507b95939b265a1ff13d5b5df..20619f73fdfc7752f409631d5a5dde712a175ff7 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -590,6 +590,10 @@ impl TerminalView { let mut dispatch_context = KeyContext::new_with_defaults(); dispatch_context.add("Terminal"); + if self.terminal.read(cx).vi_mode_enabled() { + dispatch_context.add("vi_mode"); + } + let mode = self.terminal.read(cx).last_content.mode; dispatch_context.set( "screen",