Skip to content

Harden keybinding parsing, modes/conflicts, and chord coverage#68

Merged
RtlZeroMemory merged 4 commits into
mainfrom
keybinding-hardening
Feb 18, 2026
Merged

Harden keybinding parsing, modes/conflicts, and chord coverage#68
RtlZeroMemory merged 4 commits into
mainfrom
keybinding-hardening

Conversation

@RtlZeroMemory

Copy link
Copy Markdown
Owner

Summary

This PR hardens the existing keybinding system without adding new syntax/features. It audits and tightens parsing, chord/mode behavior, and conflict resolution, then adds deterministic regression coverage and updates docs.

Fixes

  • Reject duplicate modifiers in key strings (e.g. ctrl+ctrl+a).
  • Make same-sequence re-registration replace the prior binding in mode registration flows.
  • Make setMode() throw for unknown/unregistered modes (clear error).
  • Preserve handler-driven mode changes during app key routing so they apply to subsequent events.

Tests Added

New deterministic suites under packages/core/src/keybindings/__tests__/:

  • keybinding.parse.test.ts
  • keybinding.chord.test.ts
  • keybinding.modes.test.ts
  • keybinding.conflicts.test.ts
  • keybinding.mode-switch.test.ts

The new suites cover parser edge cases, chord matching/timeout semantics, mode inheritance/switching, routing/conflict precedence, and integration behavior around handler-triggered mode switches.

Documentation

  • Updated docs/guide/input-and-focus.md with a consolidated Keybinding System section documenting syntax, chord behavior, mode rules, conflict resolution, and routing order.

Validation

  • npm run lint
  • npm run build
  • npm run typecheck
  • node scripts/run-tests.mjs

All commands pass on this branch.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01764395cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +742 to 744
const keyResult = routeKeyEvent(routeInputState, ev, keyCtx);
applyRoutedKeybindingState(routeInputState, keyResult.nextState);
if (keyResult.consumed) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Propagate keybinding handler failures before consuming input

This routing path applies keyResult.nextState and consumes the event without checking keyResult.handlerError, so handler exceptions are silently dropped in app runtime. That became user-visible in this commit because setMode() now throws for unknown modes: a typo like app.setMode("inert") inside a keybinding handler is swallowed here, the key is still treated as consumed, and no fatal/error is surfaced, making mode bugs hard to diagnose.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 220d04c.

createApp now checks keyResult.handlerError after keybinding routing (for both raw key events and synthetic key events from text input), enqueues ZRUI_USER_CODE_THROW, and stops processing the batch.

Added regression test: unknown mode switch inside keybinding handler surfaces fatal error in packages/core/src/keybindings/__tests__/keybinding.mode-switch.test.ts.

@RtlZeroMemory
RtlZeroMemory merged commit d4a5e7f into main Feb 18, 2026
18 checks passed
@RtlZeroMemory
RtlZeroMemory deleted the keybinding-hardening branch February 19, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant