facebook / lexical

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

Bug: Inconsistent behavior of `trimTextContentFromAnchor` on paste #3775

Open giacomoran opened 1 year ago

giacomoran commented 1 year ago

Lexical version: 0.7.6

Steps To Reproduce

  1. Open Lexical Playground with the "Max Length" setting on: https://playground.lexical.dev/?isMaxLength=true
  2. Clear the editor
  3. Paste some text longer than 30 character (the max length enforced with MaxLengthPlugin in Lexical Playground)
  4. Clear the editor
  5. Type any character, then repeat step 3.

At step 3. the pasted text is truncated at the maximum length. At step 5. no text is pasted. trimTextContentFromAnchor reverts to the previous editor state.

My intuition is that the behavior at step 3. is correct.

777PolarFox777 commented 1 year ago

Hello, I'm facing the same issue, it looks like there's a special logic to revert state instead of actually perform a trim. And that's definitely not what you expect when calling this method, I'd like my text to trim instead of just not being pasted.

image
pzkahoot commented 1 year ago

Are there any plans to fix this? Pasted text should trimmed to max length instead of doing nothing.