lexical icon indicating copy to clipboard operation
lexical copied to clipboard

[WIP][lexical-playground] Bug Fix: Layout deletion when it's the first node

Open kirandash opened this issue 10 months ago • 2 comments

Description

Current behavior:

  • Currently, when a layout is the first node in the editor, selecting all content and deleting (either through keyboard or mouse selection) leads to an invalid state of the widget. This issue only occurs when the layout is the first node - if there's a paragraph before the layout, deletion works correctly.

Changes being added:

  • Added $handleLayoutDelete function in LayoutPlugin to properly handle layout deletion
  • Added command registrations for all delete operations (character, word, line)
  • Added comprehensive e2e tests to verify deletion behavior in various scenarios

Closes #6938

Test plan

Before

https://github.com/user-attachments/assets/068a5e77-44e4-4f16-a587-fcd0b89fcfe2

After

The following test cases have been added to verify the fix:

  • Layout deletion when it's the first node
  • Layout deletion with surrounding content
  • Testing different delete operations:
    • Regular delete/backspace
    • Word delete (Ctrl+Backspace)
    • Line delete (Cmd+Backspace)

All tests pass and verify that:

  1. Layout deletion works correctly regardless of its position
  2. Selection and deletion work properly from both inside and outside the layout
  3. Editor maintains a valid state after deletion

https://github.com/user-attachments/assets/d0946815-3ada-4f33-bb77-942e780b1bb7

kirandash avatar Mar 09 '25 12:03 kirandash

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 9, 2025 0:53am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 9, 2025 0:53am

vercel[bot] avatar Mar 09 '25 12:03 vercel[bot]

I haven’t looked at this at all yet but usually this type of thing is handled with collapseAtStart rather than command listeners

etrepum avatar Mar 09 '25 14:03 etrepum