diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs index 73e7c9592..1412dbc89 100644 --- a/config/src/keyassignment.rs +++ b/config/src/keyassignment.rs @@ -520,6 +520,8 @@ pub enum KeyAssignment { one_shot: bool, #[dynamic(default)] until_unknown: bool, + #[dynamic(default)] + prevent_fallback: bool, }, PopKeyTable, ClearKeyTableStack, diff --git a/wezterm-gui/src/termwindow/keyevent.rs b/wezterm-gui/src/termwindow/keyevent.rs index e2a3c758e..f7f75f64e 100644 --- a/wezterm-gui/src/termwindow/keyevent.rs +++ b/wezterm-gui/src/termwindow/keyevent.rs @@ -1,7 +1,7 @@ use crate::termwindow::InputMap; use ::window::{DeadKeyStatus, KeyCode, KeyEvent, Modifiers, RawKeyEvent, WindowOps}; use anyhow::Context; -use config::keyassignment::KeyTableEntry; +use config::keyassignment::{KeyAssignment, KeyTableEntry}; use mux::pane::{Pane, PerformAssignmentResult}; use smol::Timer; use std::rc::Rc; @@ -16,6 +16,7 @@ pub struct KeyTableStateEntry { /// Whether this activation pops itself after recognizing a key press one_shot: bool, until_unknown: bool, + prevent_fallback: bool, /// The timeout duration; used when updating the expiration timeout_milliseconds: Option, } @@ -27,6 +28,7 @@ pub struct KeyTableArgs<'a> { pub replace_current: bool, pub one_shot: bool, pub until_unknown: bool, + pub prevent_fallback: bool, } #[derive(Debug, Default, Clone)] @@ -46,6 +48,7 @@ impl KeyTableState { .map(|ms| Instant::now() + Duration::from_millis(ms)), one_shot: args.one_shot, until_unknown: args.until_unknown, + prevent_fallback: args.prevent_fallback, timeout_milliseconds: args.timeout_milliseconds, }); } @@ -116,6 +119,19 @@ impl KeyTableState { if stack_entry.until_unknown { pop_count += 1; } + + if stack_entry.prevent_fallback { + // We can't simply return None for this case, as there + // may be later phases of key lookup. + // Instead, we synthesize a Nop and return that. + result = Some(( + KeyTableEntry { + action: KeyAssignment::Nop, + }, + Some(name.to_string()), + )); + break; + } } // This is a little bit tricky: until_unknown needs to diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index e5bf3eebf..92e372d85 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -2215,6 +2215,7 @@ impl TermWindow { replace_current, one_shot, until_unknown, + prevent_fallback, } => { anyhow::ensure!( self.input_map.has_table(name), @@ -2227,6 +2228,7 @@ impl TermWindow { replace_current: *replace_current, one_shot: *one_shot, until_unknown: *until_unknown, + prevent_fallback: *prevent_fallback, }); self.update_title(); } @@ -2469,6 +2471,7 @@ impl TermWindow { replace_current, one_shot: false, until_unknown: false, + prevent_fallback: false, }); }); } @@ -2518,6 +2521,7 @@ impl TermWindow { replace_current, one_shot: false, until_unknown: false, + prevent_fallback: false, }); }); }