Skip to content

[lexical] Bug Fix: Shortcuts in a decorator's input act on the input - #8

Closed
Vedthakar wants to merge 1 commit into
mainfrom
fix/3761-decorator-input-shortcuts
Closed

Vedthakar wants to merge 1 commit into
mainfrom
fix/3761-decorator-input-shortcuts

Conversation

@Vedthakar

@Vedthakar Vedthakar commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Description

This solves issue meta#3761: some shortcuts do nothing in an input inside a decorator node, for example Ctrl+Delete / Ctrl+Backspace in the playground's poll inputs, or Cmd+A on macOS.

Current behavior. The editor's keydown listener on the root also gets keydowns from a decorator's own <input>. Its shortcut table runs them as editor shortcuts. The prevent(...) shortcuts and select all call event.preventDefault() before dispatching their command:

  • delete word (Ctrl/Alt+Backspace/Delete) and, on Apple, delete line and Ctrl+H/D/K
  • format (Mod+B/I/U)
  • undo / redo
  • select all (Mod+A)
  • Ctrl+O on Apple

So the browser never deletes the word or selects the input's text, and the command acts on the editor's selection instead. beforeinput and input already skip a decorator's captured input (meta#8740, via isInputEventTargetingCapturedSelection), but keydown didn't.

What this changes.

  • Those shortcuts return without calling preventDefault() or dispatching when the keydown targets a decorator's captured input. This reuses the same helper, renamed isEventTargetingCapturedSelection and widened to KeyboardEvent. It checks the composed target, then falls back to the deep active element, as for beforeinput.
  • The keyboard copy/cut path, which preventDefault()s only for a non-range selection, gets the same check. That way Mod+C/X in the input isn't cancelled at keydown while a decorator is node-selected. This is compatible with open PR [lexical-plain-text][lexical-rich-text] Bug Fix: Leave a copy, cut or paste in a decorator's input to the input meta/lexical#9288, which handles the clipboard events themselves.
  • Shortcuts that only dispatch (arrows, Enter, Space, Backspace, Delete, Escape, Tab, Home/End) are unchanged. Their handlers already decide for themselves, and plugins may listen for them from decorators.
  • In a decorator's input, undo/redo now act on the input (not the editor's history), and format shortcuts and Ctrl+O are no longer cancelled, the same as in any <input> on the page.
  • Nothing changes for keydowns in the editor's own content.

Closes meta#3761

Test plan

New browser test packages/lexical/src/__tests__/browser/Issue3761DecoratorInputShortcuts.test.ts, with a block decorator holding an <input>:

  • For Word+Backspace, Word+Delete (Ctrl, or Alt on Apple), Mod+A, Mod+B and Mod+Z (and Cmd+Backspace on Apple), a keydown in the input is not defaultPrevented and doesn't dispatch the command.
  • Mod+C and Mod+X in the input while the decorator is node-selected: the NodeSelection is kept, the keydown is not defaultPrevented, and COPY/CUT_COMMAND isn't dispatched.
  • Control for each one: the same keydown in the editor content is still defaultPrevented and dispatches its command once.
  • "a real Ctrl/Alt+Backspace deletes a word in the input": with trusted key presses, hello world becomes hello , and the editor is unchanged.
  • "a real select all selects only the input": with trusted key presses, the input's text is selected and replaced by typing, and the editor is unchanged.

Before

On main with the test applied and the source change reverted:

$ pnpm exec vitest --project browser --no-watch packages/lexical/src/__tests__/browser/Issue3761DecoratorInputShortcuts.test.ts
  × Word+Backspace in the input is left to the input
  × Word+Delete in the input is left to the input
  × Mod+A in the input is left to the input
  × Mod+B in the input is left to the input
  × Mod+Z in the input is left to the input
  × Mod+C in the input of a node-selected decorator is left to the input
  × Mod+X in the input of a node-selected decorator is left to the input
  × a real Ctrl/Alt+Backspace deletes a word in the input   (expected 'hello world' to be 'hello ')
  × a real select all selects only the input                (expected [ 11, 11 ] to deeply equal [ 0, 11 ])
  Tests  9 failed | 7 passed (16)

After

  Issue3761DecoratorInputShortcuts: 16 passed
  test-unit: 388 files, 9403 passed | 1 skipped (includes the keydown dispatch parity tests)
  test-browser: 70 files, 907 passed | 2 skipped
  tsc, flow, eslint, prettier: clean
  e2e (chromium) KeyboardShortcuts, SelectAllDelete, History, Keyboard: 35 passed, 1 skipped

Author: Ved Thakar (@Vedthakar)

Keydown shortcuts that preventDefault (word/line delete, select all,
format, undo/redo, Ctrl+O, copy/cut of a non-range selection) also ran
when a decorator's own input had the focus, so eg. Ctrl+Backspace or
Cmd+A did nothing in it. Skip them when the keydown targets a captured
decorator input, as beforeinput/input already do.

Signed-off-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vedthakar
Vedthakar force-pushed the fix/3761-decorator-input-shortcuts branch from 2409623 to 0ce5803 Compare October 21, 2026 21:37
@Vedthakar

Copy link
Copy Markdown
Owner Author

Superseded by meta#9428.

@Vedthakar Vedthakar closed this Oct 21, 2026
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.

Bug: can't use some shortcuts in inputs inside DecoratorNodes

1 participant