facebook / lexical

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

Bug: Pressing an enter counts as 2 characters by count characters plugin #4914

Open MaxBrokhman opened 1 year ago

MaxBrokhman commented 1 year ago

Lexical version: 0.11.3

Steps To Reproduce

  1. Open the lexical playground and enable any of the char limit plugins
  2. Clear the editor and press an enter button.
  3. One new line character is counter as 2.
image

Link to code example: https://playground.lexical.dev/?isCharLimitUtf8=true

The current behavior

Pressing an enter counts as 2 characters

The expected behavior

Pressing an enter counts as 1 character

CanRau commented 1 year ago

I guess that's because Enter in the playground creates a new paragraph, still might be nice to only count as 1, if you press Shift+Enter it inserts a line-break instead of new paragraph and counting works as you'd expect

Just copy pasted the CharacterLimitPlugin and in my case, not creating new paragraphs on enter it works as expected.

CanRau commented 1 year ago

More confusing problem I face, which also happens in the playground, is that having a line-break, so a 2nd paragraph causes it to fail to properly wrap letters in OverflowNodes, it only starts when the counter reaches -3 as shown in the screenshot, trying to debug this, I think the accumulatedLength and or previousAccumulatedLength are properly calculated, at least with more than 1 paragraph present. Just crashed my browser looking more into it after restarting 😅

Screen Shot 2023-09-26 at 17 00 28

update: Yea can't wrap my head around it currently 😇 still lot's to learn 🤓

2wheeh commented 7 months ago
image

The gap between the remaining characters and overflow nodes still happens with enter