Skip to content

[lexical-playground] Bug Fix: clear block alignment and indent with a collapsed selection but not a partial one#8666

Open
achaljhawar wants to merge 1 commit into
facebook:mainfrom
achaljhawar:fix/clear-formatting-block-alignment
Open

[lexical-playground] Bug Fix: clear block alignment and indent with a collapsed selection but not a partial one#8666
achaljhawar wants to merge 1 commit into
facebook:mainfrom
achaljhawar:fix/clear-formatting-block-alignment

Conversation

@achaljhawar

Copy link
Copy Markdown
Contributor

Description

Clear formatting did nothing on a collapsed selection, so alignment set without selecting text could never be cleared (#7383). It also wiped a paragraph's alignment when you only selected one word in it.

Now a collapsed selection resets the caret block's alignment/indent, and a ranged selection only resets them when the whole block is selected. This follows the review feedback on #8237: the fully-selected check is done with carets after selection.extract(), and the empty aligned paragraph case works too.

Closes #7383

Test plan

Unit tests for the cases asked for in the #8237 review (full, partial, collapsed, empty block, cross-paragraph), plus an e2e test. Existing ClearFormatting e2e tests pass.

Before

Lexical.Playground.15.mp4

After

Lexical.Playground.14.mp4

@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 Jun 10, 2026
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 10, 2026 8:57am
lexical-playground Ready Ready Preview, Comment Jun 10, 2026 8:57am

Request Review

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.

LGTM — Clear block alignment/indent with collapsed selection (fixes #7383).

What I verified:

  • Uses $isBlockFullySelected() with CaretRange to only clear block format when the entire block is selected; collapsed selection resets just the caret block's format/indent.
  • Scoped to the lexical-playground toolbar utility only — no library/runtime impact.
  • 5 unit tests + 1 e2e test covering the relevant cases.
  • CI all green (unit 22.x + 24.x, browser, integrity, e2e canary chromium, CLA, Vercel).

No concerns. Safe to land.

@levensta

Copy link
Copy Markdown
Contributor

I also made $isBlockFullySelected function in my PR #8532, although my implementation depends on RangeSelection rather than CaretRange

Perhaps it makes sense for us to sync and leave someone else's implementation in lexical/utils. I'd like to hear your opinion and that of the maintainer.

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.

Bug: [lexical-playground] clear-formatting doesn't clear text-left/right/center alignment when no formatting to text

3 participants