1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 23:21:08 +03:00

keys: add prevent_fallback option for ActivateKeyTable

The behavior is to prevent falling back to a later key table
if no key matched.

refs: https://github.com/wez/wezterm/issues/2702
This commit is contained in:
Wez Furlong 2022-11-04 07:02:36 -07:00
parent 36903c0a1e
commit 6aceb97ded
3 changed files with 23 additions and 1 deletions

View File

@ -520,6 +520,8 @@ pub enum KeyAssignment {
one_shot: bool,
#[dynamic(default)]
until_unknown: bool,
#[dynamic(default)]
prevent_fallback: bool,
},
PopKeyTable,
ClearKeyTableStack,

View File

@ -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<u64>,
}
@ -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

View File

@ -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,
});
});
}