Skip to content

[lexical-plain-text][lexical-rich-text] Bug Fix: Leave a copy, cut or paste in a decorator's input to the input - #9288

Merged
etrepum merged 7 commits into
meta:mainfrom
rinarakaki:fix/clipboard-in-decorator-input
Oct 27, 2026
Merged

etrepum merged 7 commits into
meta:mainfrom
rinarakaki:fix/clipboard-in-decorator-input

Conversation

@rinarakaki

Copy link
Copy Markdown
Contributor

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 #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.

🤖 Generated with Claude Code

… 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]>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 30, 2026
@vercel

vercel Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Oct 27, 2026 5:59pm UTC
lexical-playground Ready Ready Preview Oct 27, 2026 5:59pm UTC

Request Review

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Browser tests fail in firefox

claude added 2 commits October 5, 2026 18:29
…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]>
@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9288

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9288

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9288

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9288

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9288

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9288

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9288

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9288

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9288

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9288

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9288

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9288

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9288

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9288

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9288

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9288

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9288

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9288

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9288

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9288

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9288

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9288

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9288

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9288

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9288

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9288

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9288

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9288

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9288

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9288

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9288

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9288

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9288

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9288

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9288

commit: 2202045

claude and others added 2 commits October 27, 2026 17:37
…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
etrepum added this pull request to the merge queue Oct 27, 2026
Merged via the queue into meta:main with commit e7baf73 Oct 27, 2026
50 checks passed
@zurfyx zurfyx mentioned this pull request Oct 28, 2026
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

2 active deployments
Preview – lexical — 22020457 Deployed Oct 27, 2026 by vercel[bot]
Preview – lexical-playground — 22020457 Deployed Oct 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: [lexical-plain-text][lexical-rich-text] A copy, cut or paste inside a decorator's input acts on the editor's selection

3 participants