WIP wk18: failing test and prefixed key lookup
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VdfEGXA7aJ6ftMsCc9PJze
This commit is contained in:
@@ -886,6 +886,25 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// improvise-wk18: a key the pages name is looked up, never typed. The only
|
||||
/// hand-written row left is an ex-command. See `context/test-evidence/protocol.md`.
|
||||
#[test]
|
||||
fn no_help_row_spells_a_key_by_hand() {
|
||||
let spelled: Vec<&str> = pages()
|
||||
.iter()
|
||||
.flat_map(|page| page.lines.iter())
|
||||
.filter_map(|line| match line {
|
||||
HelpLine::Literal { keys, .. } => Some(*keys),
|
||||
_ => None,
|
||||
})
|
||||
.filter(|keys| !keys.trim_start().starts_with(':'))
|
||||
.collect();
|
||||
assert!(
|
||||
spelled.is_empty(),
|
||||
"these rows name keys the keymap never saw: {spelled:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// `compact`'s three shapes, including the one no shipped mode reaches:
|
||||
/// keys that are all chords leave nothing to draw.
|
||||
#[test]
|
||||
|
||||
@@ -235,6 +235,32 @@ impl Keymap {
|
||||
keys
|
||||
}
|
||||
|
||||
/// Every two-key sequence here or in a parent that runs `command`: a
|
||||
/// prefix key, then a key of the sub-keymap it opens (flat, gotcha 13).
|
||||
pub fn prefixed_keys_running(
|
||||
&self,
|
||||
command: &str,
|
||||
args: Option<&[String]>,
|
||||
) -> Vec<[(KeyCode, KeyModifiers); 2]> {
|
||||
let mut keys: Vec<[(KeyCode, KeyModifiers); 2]> = self
|
||||
.bindings
|
||||
.iter()
|
||||
.filter_map(|(pattern, binding)| match (pattern, binding) {
|
||||
(KeyPattern::Key(code, mods), Binding::Prefix(sub)) => Some((*code, *mods, sub)),
|
||||
_ => None,
|
||||
})
|
||||
.flat_map(|(code, mods, sub)| {
|
||||
sub.keys_running(command, args)
|
||||
.into_iter()
|
||||
.map(move |second| [(code, mods), second])
|
||||
})
|
||||
.collect();
|
||||
if let Some(parent) = &self.parent {
|
||||
keys.extend(parent.prefixed_keys_running(command, args));
|
||||
}
|
||||
keys
|
||||
}
|
||||
|
||||
/// Look up the binding for a key in this keymap's own bindings.
|
||||
fn lookup_local(&self, key: KeyCode, mods: KeyModifiers) -> Option<&Binding> {
|
||||
self.bindings
|
||||
|
||||
Reference in New Issue
Block a user