keystroke mapper layer — intents, presets, when-clauses (T-117)

Build the upstream of every keyboard-driven feature: widgets bind
to typed Intents, the keymap resolves chord+context to an Intent,
and Flutter's Actions dispatches. The widget never touches a key.

Layers (low → high precedence):
  1. preset YAML in assets/keymaps/<preset>.yaml
  2. extension-registered command bindings (via
     KeymapService.registerCommandBinding from ExtensionManager)
  3. user file at <appDir>/keybindings.yaml
  4. settings JSON overlay at app.keymap.overrides

The when-clause grammar is a tiny recursive-descent parser over
boolean expressions on a named context bag — VS-Code style
`palette.open && !textInputFocused`. Producing services publish
scope flags via setScopeFlag.

Keys reference LogicalKeyboardKey.keyId (stable across keyboard
layouts), not the locale-aware keyLabel the consultant flagged.

Ships:
  - lib/kernel/src/keymap/{key_chord, when_clause, intents, keymap,
    keymap_service}.dart
  - assets/keymaps/default.yaml (the baseline preset)
  - 90+ unit tests covering parser precedence, layering precedence,
    scope evaluation, register/unregister, settings overlay,
    malformed-input tolerance
  - app.dart root handler routes through KeymapService → Actions
  - ExtensionManager mirrors every legacy defaultBinding into the
    keymap as a contribution layer

KeybindingResolver kept temporarily as a back-compat shim for
callers we haven't migrated yet; safe to delete once the last
caller goes through Actions.

Closes T-110 (consultant: scoped Shortcuts/Actions; off keyLabel).
Annotates T-23 with what's left for T-100. Unblocks T-64 / T-65 /
T-66 (preset data tickets).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-17 21:40:02 +02:00
co-authored by Claude Opus 4.7
parent a8729db893
commit 798ba524f1
18 changed files with 1944 additions and 47 deletions
+8
View File
@@ -14,6 +14,7 @@ import 'package:clide/kernel/src/files.dart';
import 'package:clide/kernel/src/focus.dart';
import 'package:clide/kernel/src/i18n/i18n.dart';
import 'package:clide/kernel/src/ipc/client.dart';
import 'package:clide/kernel/src/keymap/keymap_service.dart';
import 'package:clide/kernel/src/log.dart';
import 'package:clide/kernel/src/net.dart';
import 'package:clide/kernel/src/notify.dart';
@@ -40,6 +41,7 @@ class ExtensionManager extends ChangeNotifier {
required this.commands,
required this.palette,
required this.keybindings,
required this.keymap,
required this.clipboard,
required this.files,
required this.notify,
@@ -64,6 +66,7 @@ class ExtensionManager extends ChangeNotifier {
final CommandRegistry commands;
final PaletteController palette;
final KeybindingResolver keybindings;
final KeymapService keymap;
final ClideClipboard clipboard;
final FileServices files;
final Notifications notify;
@@ -171,7 +174,11 @@ class ExtensionManager extends ChangeNotifier {
commands.register(cmd);
final binding = cmd.defaultBinding;
if (binding != null) {
// Legacy KeybindingResolver still wired for back-compat
// until all callers migrate; the keymap layer is the
// canonical home for chord → command bindings (T-117).
keybindings.bind(Keybinding.parse(binding), cmd.command);
keymap.registerCommandBinding(binding, cmd.command);
}
case TrayItemContribution t:
tray.add(t);
@@ -194,6 +201,7 @@ class ExtensionManager extends ChangeNotifier {
if (binding != null) {
keybindings.unbind(Keybinding.parse(binding));
}
keymap.unregisterCommandBindings(cmd.command);
case TrayItemContribution t:
tray.remove(t.id);
case LayoutPresetContribution _: