Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
Thanks for tackling #3761! The fix works for the reported case: in the playground poll, Ctrl+Backspace in an option input now deletes a word instead of being swallowed by the editor, and the new browser test cleanly separates the old and new behavior. One issue needs addressing before this can merge.
Undo, redo and select all stop working when a non-text control inside a decorator has focus (packages/lexical/src/LexicalEvents.ts:2109, also :2191 and :2228)
isEventTargetingCapturedSelection returns true for any element inside a decorator, because the reconciler marks every decorator's DOM with setDOMUnmanaged(dom, {captureSelection: true}). So the new early return also fires when focus is on a <button> or a checkbox, where the browser has no default action for Mod+Z, Mod+Shift+Z, Ctrl+Y or Mod+A, and those keys now do nothing. To reproduce in the playground with Chrome: insert a poll, click Add Option, then press Ctrl+Z. On main the added option is undone; with this PR nothing happens. The description scopes the change to a decorator's input, and AGENTS.md's Backwards Compatibility section asks that existing behavior be kept intact otherwise.
Suggested fix: skip only for text-entry targets (a <textarea>, a text-type <input>, or a contentEditable that Lexical doesn't own), similar to how PreventSelectAllExtension limits its skip to INPUT/TEXTAREA targets (packages/lexical-extension/src/PreventSelectAllExtension.ts). A test case with a <button> inside the decorator, asserting that Mod+Z still dispatches UNDO_COMMAND, would lock this in.
Optional, non-blocking:
- The Mod+C/Mod+X cases only check that the keydown isn't cancelled. With real key presses, Ctrl+X in the input of a node-selected decorator still removes the decorator, through the native
cutevent and the rich-text cut handler. Since the description leaves the clipboard events to #9288, consider naming those two tests after what they assert. - AGENTS.md (Commits and Pull Requests) asks the Test plan's After section to paste the real command output rather than summarize it.
Keydown shortcuts that preventDefault (word/line delete, select all, format, undo/redo, Ctrl+O) also ran when an input embedded in a node's DOM had the focus, so eg. Ctrl+Backspace or Cmd+A did nothing in it. Skip them when the keydown comes from such an input, as copy and cut already do. Other controls in a decorator, such as a button, keep the editor's shortcuts. Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
0ce5803 to
316f388
Compare
|
Thanks for the review. Fixed in the latest push, which also resolves the conflict with
Added a changeset. The browser test file passes in Chromium (15 tests). — Ved Thakar |
There was a problem hiding this comment.
Thanks for picking up #3761, and for limiting the skip so a <button> inside a decorator keeps the editor's shortcuts. Two things need fixing before this can merge:
-
Non-text inputs still lose the editor's undo, redo and select all (
packages/lexical/src/LexicalEvents.ts:2132, and the same check at:2216and:2253).$isEventFromEmbeddedInputis true for any focused<input>, whatever itstype, so a checkbox, radio, range or color input inside a decorator now swallows Mod+Z, Mod+Shift+Z, Ctrl+Y and Mod+A without doing anything. To reproduce in the playground: insert a poll, vote by clicking an option's checkbox, then press Ctrl+Z. Onmainthe vote is undone; with this change nothing happens. The test's own rule ("a button has no action of its own for it") applies to these inputs too. Restricting the skip to text-entry targets (a<textarea>, a foreign contentEditable, or an<input>whosetypeis notbutton,checkbox,color,file,image,radio,range,resetorsubmit) keeps the fix, and a checkbox case in the browser test would cover it. If you add a helper for this, keep any lookup table inside the function rather than at module scope (see "Tree-shaking annotations" in AGENTS.md). -
The new test fails the TypeScript check (
packages/lexical/src/__tests__/browser/Issue3761DecoratorInputShortcuts.test.ts:139).getFirstDescendantno longer takes a type argument onmain, sotsc -p ./tsconfig.test.json(part ofpnpm run ci-check) reports TS2558 and TS2339 on that line, and thecore-tests / integrityjob is red. Narrowing works instead:const text = $getRoot().getFirstDescendant(); assert($isTextNode(text)); text.select(6, 6);
(import
$isTextNodeand drop the now-unusedTextNodetype import).
Optional, non-blocking:
- The changeset could carry a
Verify:paragraph, since the fix changes editing behaviour (undo in a decorator's input now acts on the input). CONTRIBUTING.md ("Changesets") and.changeset/README.mdask for one on such a fix, for example:Verify: keyboard shortcuts (Mod+Z, Mod+A, Ctrl/Alt+Backspace, Mod+B) pressed in an input or textarea inside a decorator; the editor's undo and formatting no longer run for them. - The Test plan still describes an earlier version of the branch (Mod+C/Mod+X cases, a helper rename, 16/18 tests, a clean
tsc). AGENTS.md ("Commits and Pull Requests") asks for the real Before and After output, so it would help to re-run the test and paste the output for the current file.
| key, | ||
| modifiers, | ||
| onMatch: (event, editor) => { | ||
| if ($isEventFromEmbeddedInput(event)) { |
There was a problem hiding this comment.
$isEventFromEmbeddedInput is true for any focused <input>, whatever its type ($isSelectionCapturedInDecoratorInput checks only nodeName === 'INPUT'), so a checkbox, radio, range or color input inside a decorator now swallows Mod+Z, Mod+Shift+Z, Ctrl+Y and Mod+A without doing anything. In the playground: insert a poll, vote with an option's checkbox, press Ctrl+Z; main undoes the vote, this branch does nothing. Skipping only for text-entry targets (a <textarea>, a foreign contentEditable, or an <input> whose type is not button/checkbox/color/file/image/radio/range/reset/submit) keeps the fix; the same applies to the Ctrl+O and select-all branches below. A checkbox case in the browser test would cover it.
| root.focus(); | ||
| editor.update( | ||
| () => { | ||
| $getRoot().getFirstDescendant<TextNode>()!.select(6, 6); |
There was a problem hiding this comment.
getFirstDescendant no longer takes a type argument on main, so tsc -p ./tsconfig.test.json reports TS2558 and TS2339 here and core-tests / integrity is red. Narrowing works:
const text = $getRoot().getFirstDescendant();
assert($isTextNode(text));
text.select(6, 6);(import $isTextNode, drop the TextNode type import).
| 'lexical': patch | ||
| --- | ||
|
|
||
| [fix] Keyboard shortcuts such as Ctrl+Backspace, Cmd+A, Cmd+B and Cmd+Z pressed in an input inside a decorator node now act on that input instead of running the editor's command |
There was a problem hiding this comment.
Optional: this fix changes editing behaviour, so CONTRIBUTING.md ("Changesets") asks for a Verify: paragraph, e.g.
Verify: keyboard shortcuts (Mod+Z, Mod+A, Ctrl/Alt+Backspace, Mod+B) pressed in an input or textarea inside a decorator; the editor's undo and formatting no longer run for them.getFirstDescendant no longer takes a type argument on main. Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
$isEventFromEmbeddedInput is true for any <input>, so a checkbox, radio or range input in a decorator swallowed undo, redo and select all without doing anything with them. Skip the editor's shortcut only for an input that takes text. Add a checkbox case to the browser test and a Verify paragraph to the changeset. Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Thanks, both fixed in the latest push:
Also added the — Ved Thakar |
Description
This solves issue #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. Theprevent(...)shortcuts and select all callevent.preventDefault()before dispatching their command:So the browser never deletes the word or selects the input's text, and the command acts on the editor's selection instead.
beforeinputandinputalready skip a decorator's captured input (#8740, viaisInputEventTargetingCapturedSelection), but keydown didn't.What this changes.
preventDefault()or dispatching when the keydown comes from a text input embedded in a node's DOM: a<textarea>, a foreign contentEditable, or an<input>of a type the user types into. This builds on$isEventFromEmbeddedInput, which [lexical-plain-text][lexical-rich-text] Bug Fix: Leave a copy, cut or paste in a decorator's input to the input #9288 added for copy, cut and paste, and excludes the<input>types that take no text (button,checkbox,color,file,image,radio,range,reset,submit).<button>or a checkbox, keep the editor's shortcuts: the browser has no action of its own for them there.mainsince [lexical-plain-text][lexical-rich-text] Bug Fix: Leave a copy, cut or paste in a decorator's input to the input #9288, so this PR does not touch them.<input>on the page.Closes #3761
Test plan
New browser test
packages/lexical/src/__tests__/browser/Issue3761DecoratorInputShortcuts.test.ts, with a block decorator holding an<input>:defaultPreventedand doesn't dispatch the command.<button>or a checkbox inside the decorator is stilldefaultPreventedand dispatchesUNDO_COMMAND.defaultPreventedand dispatches its command once.hello worldbecomeshello, and the editor is unchanged.Before
On current
mainwith the test file applied andLexicalEvents.tsfrommain(Chromium, macOS):After
On this branch (Chromium, macOS):
tsc,tsc-test, eslint and prettier on the changed files are clean. Firefox and WebKit were not run locally.Author: Ved Thakar (@Vedthakar)
🤖 Generated with Claude Code