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:
Edward Langley
2026-09-22 21:05:20 -07:00
parent a06f50560d
commit 6bdd3ad7cf
2 changed files with 45 additions and 0 deletions
+19
View File
@@ -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]
+26
View File
@@ -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