pub fn build_model(
node: NodeView,
prefix: &[KeyChord],
mode: BindingMode,
registry: &CommandRegistry,
sort: Sort,
) -> WhichKeyModelExpand description
Build the popup model from a resolved NodeView.
registry supplies rungs 2 and 3 of the label chain; pass the live
CommandRegistry. mode is only carried through for the static
catalog lookup and the model’s own field.
Labels resolve, first hit wins: the built-in catalog’s doc for the
full chord path in mode, then the registry’s doc for the bound
command, then its name, then <unbound>. An unbound child is a group
labelled +N.
§Examples
use std::sync::Arc;
use lattice_grammar::{CommandId, CommandInvocation, CommandRegistry, SourceLocation};
use lattice_keymap::{
BindingMode, BoundCommand, ChordPattern, EntryKind, KeymapLayer, KeymapTrie, Sort, build_model,
};
use lattice_protocol::KeyChord;
let bound = Arc::new(BoundCommand::from_invocation(
CommandInvocation::of(CommandId::new(1)), SourceLocation::synthetic("doc"), KeymapLayer::Builtin,
));
let lit = |c| ChordPattern::Literal(KeyChord::char(c));
let mut trie = KeymapTrie::new();
trie.insert(&[lit('g'), lit('g')], bound.clone());
trie.insert(&[lit('g'), lit('c'), lit('c')], bound);
let prefix = [KeyChord::char('g')];
let node = trie.node_view(&prefix).unwrap();
let model = build_model(node, &prefix, BindingMode::Normal, &CommandRegistry::new(), Sort::Key);
assert_eq!(model.header(), "g");
let rows: Vec<_> = model.rows().map(|(e, _)| (e.chord, e.label.as_str(), e.kind)).collect();
assert_eq!(rows, vec![
(KeyChord::char('c'), "+1", EntryKind::Prefix(1)),
// `gg` is in the built-in catalog, so its curated doc wins.
(KeyChord::char('g'), "Jump to first line", EntryKind::Terminal),
]);