facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
19.98k stars 1.7k forks source link

Bug: Removing an empty paragraph with a sibling does not correctly set styles on selection #6781

Open aleksandr-lapushkin opened 3 weeks ago

aleksandr-lapushkin commented 3 weeks ago

Lexical version: 0.19.0

Steps To Reproduce

  1. Go to the Playground
  2. Add text with a color and/or format
  3. Insert a new paragraph, set the color and format to something else
  4. Remove the paragraph character by character until the selection moves up to the previous paragraph
  5. Begin typing

https://github.com/user-attachments/assets/d2c732d8-4172-4521-934f-043088ed4915

The current behavior

  1. After typing the selection retains the style and format from the deleted paragraph

The expected behavior

  1. The inserted text should match the style and format of the selection

Impact of fix

Bug is 100% reliably reproducible and does not align with existing text editor behaviours.

The root cause might be in Selection.removeText. Specifically, when removing text in this scenario, TextNode.selectEnd is called, but it merely updates the anchor/offset. However, the style and format are not applied from the node.