Skip to content

TextStateFeature: Partial selection erases key-values from subsequent TextNodes #13386

@BoavidaGuerra

Description

@BoavidaGuerra

Describe the Bug

When applying a new (e.g.) text colour to a partial selection inside a TextNode, TextStateFeature splits the original TextNode into multiple segments (before selection, selection, after selection). However, during this split and patch process, it incorrectly discards the existing key-values (like background colour and text colour) from all resulting TextNodes after the selection.

Expected:

  • The key-values (background and text colours) remain intact on all unselected portions.
  • Only the selected portion receives the new text colour override.

Actual:

  • All text following the selection loses the previously applied key-values.

Link to the code that reproduces this issue

https://github.com/BoavidaGuerra/payload/tree/reproduction/text-state-feature-bug

Reproduction Steps

  1. create a TextNode:
Image
  1. apply a background colour and text colour to the TextNode.:
Image
  1. select a portion of that TextNode and apply a different text colour
Image

The expectation is:

Image

But outcome is:

Image

Which area(s) are affected? (Select all that apply)

plugin: richtext-lexical

Environment Info

Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: N/A
  pnpm: 9.7.1
Relevant Packages:
  payload: 3.50.0
  next: 15.4.4
  @payloadcms/db-postgres: 3.50.0
  @payloadcms/live-preview-react: 3.50.0
  @payloadcms/translations: 3.50.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:43 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T8132
  Available memory (MB): 32768
  Available CPU cores: 10

Metadata

Metadata

Assignees

Labels

dependency-issueThe issue is in a dependency of payload - not payload itselfplugin: richtext-lexical@payloadcms/richtext-lexical

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions