dispatchKeyEvent method

bool dispatchKeyEvent(
  1. KeyEvent event,
  2. FluentDocument document, {
  3. BuildContext? buildContext,
})

Implementation

bool dispatchKeyEvent(
  KeyEvent event,
  FluentDocument document, {
  BuildContext? buildContext,
}) {
  if (event is! KeyDownEvent && event is! KeyRepeatEvent) return false;
  final keyboard = HardwareKeyboard.instance;
  final matches = <(FluentKeyBinding, FluentCommand)>[];
  for (final command in _commands.values) {
    for (final binding in command.keyBindings) {
      if (binding.matches(event, keyboard)) matches.add((binding, command));
    }
  }
  if (matches.isEmpty) return false;
  matches.sort((a, b) => b.$1.priority.compareTo(a.$1.priority));
  final command = matches.first.$2;
  return executeCommand(command.id, document, buildContext: buildContext);
}