keyMapFromShortcutBindings function

KeyMap keyMapFromShortcutBindings(
  1. Iterable<ShortcutBinding> bindings
)

Build a KeyMap for HelpView from shortcut bindings.

Groups by ShortcutBinding.group; each group becomes a full-help column.

Implementation

KeyMap keyMapFromShortcutBindings(Iterable<ShortcutBinding> bindings) {
  final byGroup = <String, List<KeyBinding>>{};
  for (final b in bindings) {
    byGroup
        .putIfAbsent(b.group, () => [])
        .add(
          KeyBinding.withHelp(
            [b.formattedKeys],
            b.formattedKeys,
            b.description,
          ),
        );
  }
  final short = <KeyBinding>[for (final list in byGroup.values) ...list];
  final full = [
    for (final list in byGroup.values)
      if (list.isNotEmpty) list,
  ];
  return KeyMap(shortHelp: short, fullHelp: full.isEmpty ? [short] : full);
}