Use typable command doc when keybind provides no arguments

This improves the display of the keymap popup for example, so that if
you bind a key like `C-x = ":buffer-close"` under the `<space>` menu,
the infobox shows "Close the current buffer." rather than `:buffer-close
[]`.
This commit is contained in:
Michael Davis 2025-02-01 09:10:04 -05:00
parent 8439ce5683
commit e9c16b7fc5
No known key found for this signature in database

View file

@ -633,10 +633,17 @@ impl std::str::FromStr for MappableCommand {
.collect::<Vec<String>>();
typed::TYPABLE_COMMAND_MAP
.get(name)
.map(|cmd| MappableCommand::Typable {
name: cmd.name.to_owned(),
doc: format!(":{} {:?}", cmd.name, args),
args,
.map(|cmd| {
let doc = if args.is_empty() {
cmd.doc.to_string()
} else {
format!(":{} {:?}", cmd.name, args)
};
MappableCommand::Typable {
name: cmd.name.to_owned(),
doc,
args,
}
})
.ok_or_else(|| anyhow!("No TypableCommand named '{}'", s))
} else if let Some(suffix) = s.strip_prefix('@') {