Repository navigation
[lexical-plain-text][lexical-rich-text] Bug Fix: Leave a copy, cut or paste in a decorator's input to the input - #9288
Merged
Conversation
… paste in a decorator's input to the input ## Description A copy, cut or paste inside a decorator's own input, such as an `<input>` in its DOM, bubbles to the editor's root, and the root's listeners dispatch `COPY_COMMAND`, `CUT_COMMAND` or `PASTE_COMMAND` for it. The editor still holds the selection it had before the input took the focus, since a selection inside a decorator's input isn't read back. - **Plain text:** all three listeners act on that selection. A copy is prevented and puts the editor's selection on the clipboard. A cut does the same and deletes it from the document. A paste writes into the document instead of the input. - **Rich text:** copy and paste are already left to the input. A cut isn't: the input cuts its own text, and `onCutForRichText` also removes the editor's selection after its copy. With this change, plain text's three clipboard listeners and rich text's cut listener return `false` for an event from a decorator's input. They make the check rich text's paste listener already makes, `$isSelectionCapturedInDecoratorInput` on the event's target, which is read with `getComposedEventTarget`. The browser then performs the input's own copy, cut or paste, and the document is left alone. Copies, cuts and pastes in the editor's own text are unchanged. Closes meta#9278 ## Test plan New browser tests press the real shortcuts (Ctrl or Cmd with C, X or V) in a decorator's `<input>`. `hello` is selected in the editor and `field` in the input. The same keys pressed in the editor's own text are the controls. Each test reads the clipboard event as the page sees it once the editor's listeners have run: whether they prevented the browser's action, and the text they wrote. The tests don't read the system clipboard, which test files running at the same time share. ### Before The same tests without the change to the two listeners: ``` $ pnpm exec vitest --project browser --no-watch packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts packages/lexical-rich-text/src/__tests__/browser/RichTextDecoratorInputClipboard.test.ts FAIL |browser (chromium)| packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in a decorator input > copy in the input is left to the input AssertionError: expected { defaultPrevented: true, …(1) } to deeply equal { Object (defaultPrevented, written) } - Expected + Received { - "defaultPrevented": false, - "written": "", + "defaultPrevented": true, + "written": "hello", } FAIL |browser (chromium)| packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in a decorator input > cut in the input is left to the input AssertionError: expected { defaultPrevented: true, …(1) } to deeply equal { Object (defaultPrevented, written) } - Expected + Received { - "defaultPrevented": false, - "written": "", + "defaultPrevented": true, + "written": "hello", } FAIL |browser (chromium)| packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in a decorator input > paste in the input is left to the input AssertionError: expected true to be false // Object.is equality - Expected + Received - false + true FAIL |browser (chromium)| packages/lexical-rich-text/src/__tests__/browser/RichTextDecoratorInputClipboard.test.ts > RichTextExtension clipboard in a decorator input > cut in the input is left to the input AssertionError: expected ' world ' to be 'hello world ' // Object.is equality Expected: "hello world " Received: " world " Test Files 2 failed (2) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm exec vitest --project browser --no-watch packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts packages/lexical-rich-text/src/__tests__/browser/RichTextDecoratorInputClipboard.test.ts ✓ packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in a decorator input > copy in the input is left to the input 97ms ✓ packages/lexical-rich-text/src/__tests__/browser/RichTextDecoratorInputClipboard.test.ts > RichTextExtension clipboard in a decorator input > copy in the input is left to the input 96ms ✓ packages/lexical-rich-text/src/__tests__/browser/RichTextDecoratorInputClipboard.test.ts > RichTextExtension clipboard in a decorator input > cut in the input is left to the input 66ms ✓ packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in a decorator input > cut in the input is left to the input 66ms ✓ packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in a decorator input > paste in the input is left to the input 68ms ✓ packages/lexical-rich-text/src/__tests__/browser/RichTextDecoratorInputClipboard.test.ts > RichTextExtension clipboard in a decorator input > paste in the input is left to the input 68ms ✓ packages/lexical-rich-text/src/__tests__/browser/RichTextDecoratorInputClipboard.test.ts > RichTextExtension clipboard in a decorator input > cut in the editor cuts the editor selection 18ms ✓ packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in a decorator input > copy in the editor copies the editor selection 18ms ✓ packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in a decorator input > cut in the editor cuts the editor selection 12ms ✓ packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in a decorator input > paste in the editor is the editor's 17ms Test Files 2 passed (2) Tests 10 passed (10) $ pnpm exec vitest --project browser --no-watch Test Files 37 passed (37) Tests 265 passed | 1 skipped (266) $ pnpm exec vitest --project unit --no-watch packages/lexical-clipboard packages/lexical-history packages/lexical-html/src/__tests__/unit/DOMImportExtension.test.ts packages/lexical-link packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx packages/lexical-table packages/lexical-rich-text packages/lexical-utils packages/lexical/src/__tests__/unit Test Files 153 passed (153) Tests 2444 passed (2444) ``` `pnpm run tsc` and `pnpm run tsc-test` pass, and prettier and eslint are clean on the changed files. Removing any one of plain text's three checks fails only its own test. The browser tests ran in Chromium only; Firefox and WebKit weren't run. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
rinarakaki
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
September 30, 2026 11:28
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Sep 30, 2026
etrepum
left a comment
Collaborator
There was a problem hiding this comment.
Browser tests fail in firefox
…y or cut in a node-selected decorator's input to the input
## Description
When the editor's selection is a NodeSelection, which is the usual state after clicking a selectable decorator, core's Cmd/Ctrl+C and Cmd/Ctrl+X keydown shortcut prevents the key press and dispatches COPY_COMMAND or CUT_COMMAND with the KeyboardEvent. It did that for a key press in the decorator's own `<input>` as well, so the browser never fired the input's copy or cut. Rich text then copied the selected decorator instead of the input's text, and before the previous commit a cut deleted the decorator.
The shortcut now leaves a key press from a decorator's input alone, so the browser performs the input's own copy or cut. The check is a new `$isEventFromDecoratorInput(event)` in `lexical`, which reads the event's composed target with `$isSelectionCapturedInDecoratorInput`. Plain text's copy, cut and paste listeners and rich text's copy, cut and paste listeners all use it in place of their own versions of the check, and rich text's copy listener now makes it too.
## Test plan
New browser tests select the decorator, select `field` in its `<input>`, and press Cmd/Ctrl+C or Cmd/Ctrl+X, in plain text and in rich text.
### Before
Without the change to the keydown shortcut:
```
$ pnpm exec vitest --project browser --no-watch DecoratorInputClipboard
FAIL |browser (chromium)| packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in the input of a node-selected decorator > copy in the input is left to the input
AssertionError: expected [] to have a length of 1 but got +0
FAIL |browser (chromium)| packages/lexical-plain-text/src/__tests__/browser/PlainTextDecoratorInputClipboard.test.ts > PlainTextExtension clipboard in the input of a node-selected decorator > cut in the input is left to the input
AssertionError: expected [] to have a length of 1 but got +0
FAIL |browser (chromium)| packages/lexical-rich-text/src/__tests__/browser/RichTextDecoratorInputClipboard.test.ts > RichTextExtension clipboard in the input of a node-selected decorator > copy in the input is left to the input
AssertionError: expected [] to have a length of 1 but got +0
FAIL |browser (chromium)| packages/lexical-rich-text/src/__tests__/browser/RichTextDecoratorInputClipboard.test.ts > RichTextExtension clipboard in the input of a node-selected decorator > cut in the input is left to the input
AssertionError: expected [] to have a length of 1 but got +0
Tests 4 failed | 10 passed (14)
```
### After
```
$ pnpm exec vitest --project browser --no-watch DecoratorInputClipboard
Tests 14 passed (14)
$ pnpm exec vitest --project browser --no-watch
Test Files 62 passed (62)
Tests 675 passed | 2 skipped (677)
$ pnpm exec vitest --project unit --no-watch packages/lexical/src packages/lexical-rich-text packages/lexical-plain-text packages/lexical-clipboard packages/lexical-table packages/lexical-react
Test Files 175 passed (175)
Tests 2720 passed (2720)
$ pnpm exec vitest --no-watch scripts/__tests__/unit/treeShaking
Tests 340 passed (340)
```
`pnpm run tsc` and `pnpm run flow` pass, and eslint and prettier are clean. The browser tests ran in Chromium only; Firefox and WebKit weren't run.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…y, cut or paste in an input in any node's unmanaged DOM to the input
## Description
Any node can render an `<input>` beside its children or text as unmanaged DOM, through `createDOM`, a DOM slot or a `DOMRenderExtension` override, not only a decorator. On main a copy, cut or paste in such an input in a paragraph was handled by the editor with its stale selection, like the decorator case, and a paste in one inside a text node's DOM was written into the document in plain text.
The check the previous commit added already covers these inputs, since `$isSelectionCapturedInDecoratorInput` accepts any input whose nearest Lexical node exists. This commit renames the new helper to `$isEventFromEmbeddedInput`, so its name doesn't suggest only decorators, documents the cases it covers, and adds browser tests for an input that a render override places ahead of a paragraph's children and ahead of a text node's text.
## Test plan
### Before
The new tests against main's plain text and rich text listeners:
```
$ pnpm exec vitest --project browser --no-watch UnmanagedInputClipboard
FAIL |browser (chromium)| packages/lexical-plain-text/src/__tests__/browser/PlainTextUnmanagedInputClipboard.test.ts > input in ParagraphNode unmanaged DOM > copy
FAIL |browser (chromium)| packages/lexical-plain-text/src/__tests__/browser/PlainTextUnmanagedInputClipboard.test.ts > input in ParagraphNode unmanaged DOM > cut
FAIL |browser (chromium)| packages/lexical-plain-text/src/__tests__/browser/PlainTextUnmanagedInputClipboard.test.ts > input in ParagraphNode unmanaged DOM > paste
FAIL |browser (chromium)| packages/lexical-plain-text/src/__tests__/browser/PlainTextUnmanagedInputClipboard.test.ts > input in TextNode unmanaged DOM > paste
FAIL |browser (chromium)| packages/lexical-rich-text/src/__tests__/browser/RichTextUnmanagedInputClipboard.test.ts > input in ParagraphNode unmanaged DOM > cut
Tests 5 failed | 7 passed (12)
```
### After
```
$ pnpm exec vitest --project browser --no-watch InputClipboard
Tests 26 passed (26)
$ pnpm exec vitest --project browser --no-watch
Test Files 64 passed (64)
Tests 687 passed | 2 skipped (689)
$ pnpm exec vitest --project unit --no-watch packages/lexical/src packages/lexical-rich-text packages/lexical-plain-text packages/lexical-clipboard packages/lexical-html
Test Files 128 passed (128)
Tests 2400 passed (2400)
```
`pnpm run tsc` and `pnpm run flow` pass, and eslint and prettier are clean. The browser tests ran in Chromium only; Firefox and WebKit weren't run.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Oct 17, 2026
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/yjs
commit: |
…ed DOM to the input in Firefox
## Description
A focused `<input>`, `<textarea>` or foreign contentEditable in a node's unmanaged DOM, such as an `<input>` that a render override adds beside a paragraph's children, still had its `beforeinput` and `input` events turned into Lexical commands unless the DOM was marked with `setDOMUnmanaged({captureSelection: true})`. Firefox gives the `insertFromPaste` input event of a paste in such an input the pasted text as its data, so `$handleInput` inserted that text at the editor's selection as well as the input taking it. This failed `paste in the input is left to the input` for `ParagraphNode` in the Firefox browser tests, in plain text and in rich text.
The guard on those events, now `$isInputEventTargetingCapturedSelection`, also leaves an event alone when the focused element is such an input, as `$isSelectionCapturedInDecoratorInput` decides. Decorator inputs were already covered, since a decorator's DOM is marked as capturing the selection.
## Test plan
### Before
```
$ VITEST_BROWSER=firefox pnpm exec vitest --project browser --no-watch
FAIL |browser (firefox)| packages/lexical-plain-text/src/__tests__/browser/PlainTextUnmanagedInputClipboard.test.ts > PlainTextExtension clipboard in an input in ParagraphNode's unmanaged DOM > paste in the input is left to the input
FAIL |browser (firefox)| packages/lexical-rich-text/src/__tests__/browser/RichTextUnmanagedInputClipboard.test.ts > RichTextExtension clipboard in an input in ParagraphNode's unmanaged DOM > paste in the input is left to the input
Test Files 2 failed | 75 passed | 1 skipped (78)
Tests 2 failed | 1047 passed | 9 skipped (1058)
AssertionError: expected 'field world ' to be 'hello world ' // Object.is equality
```
### After
```
$ VITEST_BROWSER=firefox pnpm exec vitest --project browser --no-watch
Test Files 77 passed | 1 skipped (78)
Tests 1049 passed | 9 skipped (1058)
$ VITEST_BROWSER=chromium pnpm exec vitest --project browser --no-watch
Test Files 78 passed (78)
Tests 1056 passed | 2 skipped (1058)
$ VITEST_BROWSER=webkit pnpm exec vitest --project browser --no-watch
Test Files 78 passed (78)
Tests 1059 passed | 3 skipped (1062)
$ pnpm run test-unit
Test Files 408 passed | 1 skipped (409)
Tests 10066 passed | 4 expected fail | 2 skipped (10072)
```
`pnpm run tsc` and `pnpm run flow` pass, and eslint and prettier are clean. The browser tests ran on Linux only; macOS and Windows weren't run. Before this change the Chromium e2e suite (rich text) passed on this branch: 626 passed, 36 skipped.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
etrepum
approved these changes
Oct 27, 2026
Merged
rinarakaki
added a commit
to rinarakaki/lexical
that referenced
this pull request
Nov 20, 2026
…eave an arrow key pressed in a node-selected decorator's own input to that input ## Description When a decorator renders its own `<input>` or `<textarea>` and is node-selected, clicking into that field keeps the editor's NodeSelection, and the field's `keydown` bubbles to the editor's root. Plain text's new NodeSelection branches then called `preventDefault()` and moved the editor's selection beside the node, so the field's caret stopped moving: with the caret after "field" in `field text`, every arrow key left it there, where plain text used to leave these keys to the field. Rich text's NodeSelection branches did the same already. This change: - returns `false` from plain text's `$exitNodeSelection`, and skips rich text's four NodeSelection branches, for an event `$isEventFromEmbeddedInput` reports, as the clipboard handlers do since meta#9288; - adds a browser test to each package that node-selects a decorator holding an input, clicks into the input and presses each arrow key: the keydown isn't prevented, the input's caret lands where the same key puts it in a plain `<input>` outside the editor, and the NodeSelection stays; - adds right-to-left cases for ArrowLeft and ArrowRight on a node-selected inline decorator, and checks that Shift's RangeSelection holds the rule; - reworks the TSDoc of `$convertContiguousNodeSelection` to say what it does, including that it commits the caller's update synchronously, and writes `@param name - description` as `AGENTS.md` asks; - after merging `main`, reads the test's block without `getLastChildOrThrow`'s type argument, which meta#9479 removed; - adds changesets. ## Changeset `.changeset/plain-text-node-selection-arrows.md` and `.changeset/selection-node-selection-helpers.md` ## Test plan ### Before `VITEST_BROWSER=chromium,firefox,webkit pnpm exec vitest --project browser --no-watch --reporter=verbose packages/lexical-plain-text/src/__tests__/browser/PlainTextNodeSelectionArrow.test.ts`, without the guard: ``` × |browser (chromium)| Arrow keys in the input of a node-selected decorator > ArrowLeft is left to the input → expected true to be false // Object.is equality × |browser (chromium)| Arrow keys in the input of a node-selected decorator > ArrowRight is left to the input × |browser (chromium)| Arrow keys in the input of a node-selected decorator > ArrowUp is left to the input × |browser (chromium)| Arrow keys in the input of a node-selected decorator > ArrowDown is left to the input (the same four in firefox and webkit, each `expected true to be false`: the keydown was prevented) Test Files 3 failed (3) Tests 12 failed | 42 passed (54) ``` The same command for `packages/lexical-rich-text/src/__tests__/browser/RichTextNodeSelectionArrow.test.ts`, without rich text's guard (as on `main`): ``` Test Files 3 failed (3) Tests 12 failed | 27 passed (39) ``` ### After Both files, with `PlainTextDecoratorInputClipboard.test.ts` and `RichTextDecoratorInputClipboard.test.ts`, in Chromium, Firefox and WebKit: ``` Test Files 12 passed (12) Tests 135 passed (135) ``` `pnpm exec vitest --project unit --no-watch packages/lexical-plain-text/ packages/lexical-rich-text/ packages/lexical-selection/`: ``` Test Files 33 passed (33) Tests 2104 passed | 1 expected fail (2105) ``` `VITEST_BROWSER=chromium,firefox,webkit pnpm exec vitest --project browser --no-watch packages/lexical-plain-text/ packages/lexical-rich-text/ packages/lexical-selection/`: ``` Test Files 30 passed (30) Tests 237 passed (237) ``` `pnpm run tsc`, `pnpm run flow` and `pnpm run check-changesets` pass, and ESLint and Prettier are clean on the changed files. Only Linux was run; macOS and Windows weren't.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A copy, cut or paste inside a decorator's own input, such as an
<input>in its DOM, bubbles to the editor's root, and the root's listeners dispatchCOPY_COMMAND,CUT_COMMANDorPASTE_COMMANDfor it. The editor still holds the selection it had before the input took the focus, since a selection inside a decorator's input isn't read back.onCutForRichTextalso removes the editor's selection after its copy.With this change, plain text's three clipboard listeners and rich text's cut listener return
falsefor an event from a decorator's input. They make the check rich text's paste listener already makes,$isSelectionCapturedInDecoratorInputon the event's target, which is read withgetComposedEventTarget. The browser then performs the input's own copy, cut or paste, and the document is left alone. Copies, cuts and pastes in the editor's own text are unchanged.Closes #9278
Test plan
New browser tests press the real shortcuts (Ctrl or Cmd with C, X or V) in a decorator's
<input>.hellois selected in the editor andfieldin the input. The same keys pressed in the editor's own text are the controls. Each test reads the clipboard event as the page sees it once the editor's listeners have run: whether they prevented the browser's action, and the text they wrote. The tests don't read the system clipboard, which test files running at the same time share.Before
The same tests without the change to the two listeners:
After
pnpm run tscandpnpm run tsc-testpass, and prettier and eslint are clean on the changed files. Removing any one of plain text's three checks fails only its own test. The browser tests ran in Chromium only; Firefox and WebKit weren't run.🤖 Generated with Claude Code