2.7 KiB
2.7 KiB
Keyboard Integration as Shared Input, Not as Gesture
Decision
Keyboard is not a GestureType.
v2 treats pointer gestures and keyboard events as parallel input streams that share:
- one context stack
- one resolver
- one action dispatcher
- one provider-owned keyboard listener per active canvas
Runtime Shape
- Pointer stays gesture-native:
tapdouble-taptriple-taplong-pressdragpinchscroll
- Keyboard uses a separate event shape:
kind: 'key'phase: 'down' | 'up'keycoderepeat
- Shared runtime event union:
PointerGestureEventKeyInputEventInputEvent
- Held keyboard state is explicit:
heldKeys.byKeyheldKeys.byCode
- Pointer events carry a held-key snapshot so bindings like
Space+dragare modeled as pointer gestures with keyboard context.
Resolver Rules
- Pointer patterns still match pointer gesture types.
- Keyboard patterns match
phase,key, and/orcode. keyscore:+64codescore:+64- held-key positive score:
+16 - held-key negative score:
+8 - If both
keyandcodeare present, both must match.
Ownership
InputProvideris the single keyboard owner for the active canvas.- The last canvas root to receive pointer interaction or focus becomes keyboard-active.
- Keyboard routing is suppressed when:
- target is
input - target is
textarea - target is
contentEditable - IME composition is active
- target is
- Held keys clear on
blurandvisibilitychange.
Default Behavior
/opens command lineCmd/Ctrl+Fopens searchCmd/Ctrl+C/X/V/Droute through shared input actionsCmd/Ctrl+Z,Cmd/Ctrl+Shift+Z,Cmd/Ctrl+Yroute through shared input actionsDelete/Backspacedelete current selectionEscapeprecedence:- cancel active interaction
- exit keyboard manipulate mode
- clear search / selection / close palette
keyboardInteractionModeis explicit:'navigate''manipulate'
- Navigate mode:
- arrows move focus
Enterselects and enters manipulate modeSpaceactivates focused nodeTabcycles focus
- Manipulate mode:
- arrows nudge selection by
10 Shift+Arrownudges by50Escapereturns to navigate mode
- arrows nudge selection by
Cutoff
- Remove keyboard ownership from:
packages/canvas/src/commands/keyboard.tspackages/canvas/src/hooks/useCanvasHistory.tspackages/canvas/src/hooks/useArrowKeyNavigation.ts
- Keep those exports as compatibility shims only if needed for callers during the repo migration.
Verification
- resolver tests for key/code/held-key matching
- runtime tests for
Space+drag,Escape, copy/paste, undo/redo, and active-canvas ownership - behavior tests for navigate vs manipulate mode