Skip to content

Bug: [lexical] Typing with a toggled format inside a segmented text node formats the whole node #9833

Open

Description

@zurfyx

RangeSelection.insertText with a collapsed selection inside a segmented text node, after a format was toggled on the caret, makes the whole node bold (or whatever the toggled format is), not just the typed text.

Repro (headless, no collaboration): a paragraph with zero and a segmented text node one two; caret at offset 4 of the segmented node (before two); selection.formatText('bold'); selection.insertText('new '). Result: zero plain and one new two bold. Expected: only new bold.

Cause: the segmented-node branch of $insertText (packages/lexical/src/LexicalSelection.ts, the anchorNode.isSegmented() && offset !== 0 && offset !== anchorSize case) replaces the node with a normal text node and calls replacement.setFormat(format) / setStyle(style) with the selection's format and style (and setMode('normal').setFormat(format).setStyle(style) while composing), so the existing text takes them; the recursive insertText then sees the selection's format equal to the node's and inserts without splitting. Keeping the node's own format and style on the replacement would let the recursive call split as it does for a normal node.

Found by a collaboration soak, but it is the same on its own.

Activity

  1. added a commit that references this issue on Nov 13, 2026
    b95f7ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions