Skip to content

docs(openspec): propose tool-facing keyboard events - #209

Open
gohabereg wants to merge 3 commits into
mainfrom
feat/tool-input-events
Open

gohabereg wants to merge 3 commits into
mainfrom
feat/tool-input-events

Conversation

@gohabereg

Copy link
Copy Markdown
Member

Summary

OpenSpec proposal add-tool-input-events — proposal only, no implementation.

Block tools can't react to Enter, Backspace, Tab or any other key today: the blocks holder is the single contenteditable editing host, so keydown targets the holder and listeners on a tool's own elements never fire (capture or bubble). This blocks tools like List, Code and Table.

The proposal:

  • @editorjs/dom-adapters forwards keydown to the block's tool as a bubbling, cancelable editor:keydown CustomEvent, dispatched on the tool's input element, carrying the native KeyboardEvent plus the model position (key, range, inputs).
  • Tools subscribe with plain addEventListener (on an input, or once on their wrapper).
  • Cancelling it cancels the native keydown, so the editor's default (split, delete) and plugin shortcuts don't run.
  • The tool sees the key before plugins: forwarding is one listener registered by DOMAdapters, which initializes before other plugins.
  • No behaviour change when nothing cancels.

Deferred: editor:beforeinput forwarding (needed for Android virtual keyboards / IME), Backspace merge wiring, line breaks, cross-input delete fix, re-keying inputs after array shifts.

Files: openspec/changes/add-tool-input-events/{proposal,design,tasks}.md, specs/dom-adapters/spec.md. openspec validate --strict passes.

🤖 Generated with Claude Code

gohabereg and others added 2 commits October 17, 2026 18:08
Forward keydown and beforeinput to block tools as cancelable
editor:keydown / editor:beforeinput DOM events dispatched on the
tool's input element, so tools can own Enter, Backspace, Tab and
other keys inside the single contenteditable holder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Forward only editor:keydown for now; editor:beforeinput is deferred
and documented as a known mobile/IME limitation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

At `keydown` time the adapter reads the document selection:

- a collapsed caret, or a selection whose start and end are both in inputs of the same block → that block's adapter dispatches, on the input holding the selection start;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skip forwarding when the native keydown targets a button or another non-editing control. Chromium can retain a selection in a different block after focus moves to the control, causing Enter to edit that block and cancel the control's activation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isContentEditable is inherited from the holder, so a plain <button> still returns true in Chromium and passes this guard. Exclude native controls explicitly so Enter on such a button cannot be forwarded to a stale selection in another block.

Forward editor:keydown only when the native event targets editable
content. With focus on a button inside a block, Chromium can keep the
selection in another block, so selection-only routing would let that
block's tool cancel Enter and swallow the button's activation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gohabereg
gohabereg requested a review from Reversean November 5, 2026 01:00
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