Skip to content

Leave Mod-a and Mod-z to a host element focused beside the editor - #86

Merged
janglad merged 1 commit into
mainfrom
fix/web-4152-shortcuts-often-dont-work-if-composer-is-open
Oct 6, 2026
Merged

janglad merged 1 commit into
mainfrom
fix/web-4152-shortcuts-often-dont-work-if-composer-is-open

Conversation

@janglad

@janglad janglad commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Summary

The document key handler claimed Mod-a, Mod-z and Mod-Shift-z for any mounted editor that still had a caret, even while a host element held focus. A host's own undo or select-all never saw the key: the editor undid its last edit and stopped propagation in capture.

HOST9 already says focus on a host element is the host's. Keys now follow the same ownership.

 shouldHandleEditorKeyboardEvent
   …
+  if document shortcut (Mod-a, Mod-z, Mod-Shift-z)
+     and activeElement is neither inside root nor a wrapper of root
+    return false
   if hasMappedDomSelection → true
   if document shortcut → isDocumentSelection(selection, true)

Unchanged: focus on the body, or on a focusable wrapper around the root, still routes these keys to the editor.

Spec: HOST9 in spec/rules/host.md and the gate note in spec/packages/rendering/dom.md are amended in this PR.

Evidence

  • Before: textEntryTarget.host9.test.ts, a focused host <button> beside the root with Mod-z or Mod-a: shouldHandleEditorKeyboardEvent returned true.
    After: returns false for Mod-a, Mod-z and Mod-Shift-z. Body focus and a focused wrapper still return true.
  • pen-dom typecheck and the src/utils tests pass. The full pen-dom, pen-react and pen-vue suites passed on the previous revision, which differed only by also covering Mod-y.

Merge Danger

Door: two-way

Patch changeset for @input/pen-dom, Breaking: no.

Blast Radius: keyboard-routing

  • A host that relied on Mod-z or Mod-a reaching the editor while one of its own elements held focus (a toolbar button mounted outside the root that keeps focus after a click) now receives the key itself.
  • A leftover range or block selection in an unfocused editor can still claim other keys (Backspace, Delete, arrows) under host focus. Unchanged here.
  • An editor inside a shadow root is not recognised as containing or contained, since contains does not cross the boundary.

Note

Medium Risk
Changes capture-phase routing for Mod-a/Mod-z/Mod-Shift-z; hosts that depended on editor undo/select-all while their own focused chrome sat outside the root will now receive those keys instead.

Overview
Fixes HOST9 keyboard ownership so Mod-a, Mod-z, and Mod-Shift-z are not stolen by the editor’s capture-phase document handler when focus sits on a host element beside the editor root (not inside the root and not on a wrapper that contains the root). Previously, any mounted editor with a leftover caret still routed those shortcuts to undo/select-all even while a host button or control held focus.

shouldHandleEditorKeyboardEvent in textEntryTarget.ts now returns false for document shortcuts in that focus case, before mapped-DOM-selection and selection-based routing. Unchanged: focus on document.body or on a focusable wrapper around the root still routes Mod-a/Mod-z to the editor.

Adds textEntryTarget.host9.test.ts, a patch changeset for @input/pen-dom, and spec updates in spec/rules/host.md and spec/packages/rendering/dom.md.

Reviewed by Cursor Bugbot for commit 56effc9. Bugbot is set up for automated code reviews on this repo. Configure here.

This commit introduces functionality to ensure that when a host element is focused beside the editor, keyboard shortcuts Mod-a, Mod-z, and Mod-Shift-z are correctly handled. Previously, these shortcuts were claimed by the editor, causing unintended behavior. The changes include updates to the keyboard event handling logic and the addition of tests to verify the correct behavior in various focus scenarios.

- Implemented logic to prevent the editor from claiming shortcuts when a host element is focused.
- Added tests to validate the new behavior for HOST9 scenarios.
- Updated documentation to reflect the changes in shortcut handling.

No breaking changes introduced.
@janglad

janglad commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 56effc9. Configure here.

@janglad
janglad merged commit 502c90b into main Oct 6, 2026
40 checks passed
@janglad
janglad deleted the fix/web-4152-shortcuts-often-dont-work-if-composer-is-open branch October 6, 2026 16:25
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.

2 participants