Skip to content

Commit

Permalink
keys: add prevent_fallback option for ActivateKeyTable
Browse files Browse the repository at this point in the history
The behavior is to prevent falling back to a later key table
if no key matched.

refs: #2702
  • Loading branch information
wez committed Nov 4, 2022
1 parent 36903c0 commit 6aceb97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/src/keyassignment.rs
Expand Up @@ -520,6 +520,8 @@ pub enum KeyAssignment {
one_shot: bool,
#[dynamic(default)]
until_unknown: bool,
#[dynamic(default)]
prevent_fallback: bool,
},
PopKeyTable,
ClearKeyTableStack,
Expand Down
18 changes: 17 additions & 1 deletion 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;
Expand All @@ -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>,
}
Expand All @@ -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)]
Expand All @@ -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,
});
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions wezterm-gui/src/termwindow/mod.rs
Expand Up @@ -2215,6 +2215,7 @@ impl TermWindow {
replace_current,
one_shot,
until_unknown,
prevent_fallback,
} => {
anyhow::ensure!(
self.input_map.has_table(name),
Expand All @@ -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();
}
Expand Down Expand Up @@ -2469,6 +2471,7 @@ impl TermWindow {
replace_current,
one_shot: false,
until_unknown: false,
prevent_fallback: false,
});
});
}
Expand Down Expand Up @@ -2518,6 +2521,7 @@ impl TermWindow {
replace_current,
one_shot: false,
until_unknown: false,
prevent_fallback: false,
});
});
}
Expand Down

0 comments on commit 6aceb97

Please sign in to comment.