resolveKey method

ResolveResult resolveKey(
  1. ParsedKeystroke keystroke,
  2. List<KeybindingContext> activeContexts
)

Resolve a keystroke in a list of active contexts. Pure single-keystroke matching — last registered binding wins.

Implementation

ResolveResult resolveKey(
  ParsedKeystroke keystroke,
  List<KeybindingContext> activeContexts,
) {
  final ctxSet = activeContexts.toSet();
  ParsedBinding? match;

  for (final binding in _bindings) {
    if (binding.chord.length != 1) continue;
    if (!ctxSet.contains(binding.context)) continue;
    if (keystrokesEqual(binding.chord.first, keystroke)) {
      match = binding;
    }
  }

  if (match == null) return const NoMatchResult();
  if (match.action == null) return const UnboundResult();
  return MatchResult(match.action!);
}