Skip to content

[lexical-selection] Bug Fix: style the supplied selection instead of the active selection - #9265

Closed
etrepum wants to merge 1 commit into
meta:mainfrom
etrepum:codex/fix-detached-style
Closed

etrepum wants to merge 1 commit into
meta:mainfrom
etrepum:codex/fix-detached-style

Conversation

@etrepum

@etrepum etrepum commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Description

$patchStyleText accepts a selection, but its text-node iterator reads the active selection instead. A detached range or node selection can therefore style nothing or modify unrelated selected text. Even a collapsed target can style an unrelated active range.

Share the existing iterator through a private helper that receives its selection explicitly. $patchStyleText uses its argument; the public $forEachSelectedTextNode continues to use the active selection with no API change. This fix is based on main and is independent of the caret text-slice changes in #9261.

Test plan

Additional unit test coverage

…the active selection

## Description

$patchStyleText accepts a selection, but its text-node iterator reads the active
selection instead. A detached range or node selection can therefore style
nothing or modify unrelated selected text. Even a collapsed target can style
an unrelated active range.

Share the existing iterator through a private helper that receives its selection
explicitly. $patchStyleText uses its argument; the public $forEachSelectedTextNode
continues to use the active selection with no API change. This fix is based on
main and is independent of the caret text-slice changes in meta#9261.

## Test plan

### Before

```sh
node node_modules/vitest/vitest.mjs run --project unit packages/lexical-selection/src/__tests__/unit/PatchStyleDetachedSelection.test.ts --maxWorkers=2
```

```text
 Test Files  1 failed (1)
      Tests  10 failed | 2 passed (12)
```

### After

```sh
node node_modules/vitest/vitest.mjs run --project unit packages/lexical-selection --maxWorkers=2
```

```text
 Test Files  7 passed (7)
      Tests  331 passed (331)
```

Coverage includes whole/partial/collapsed ranges and node selections with no
active selection, an unrelated caret, or an unrelated range. Checks verify that
unrelated text and active endpoints remain unchanged.

Test TypeScript, changed-file ESLint/Prettier, and git diff --check pass.
Browser tests were not run.
@vercel

vercel Bot commented Sep 28, 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 Sep 28, 2026 7:19pm UTC
lexical-playground Ready Ready Preview Sep 28, 2026 7:19pm UTC

Request Review

@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 28, 2026
@etrepum

etrepum commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #9261, which now includes this fix together with caret-based endpoint repair and tests for backward detached ranges, repaired selection points, and repeated style patches.

@etrepum etrepum closed this Sep 28, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 25eefc81 Deployed Sep 28, 2026 by vercel[bot]
Preview – lexical-playground — 25eefc81 Deployed Sep 28, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant