lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: Inconsistent behavior of `trimTextContentFromAnchor` on paste

Open giacomoran opened this issue 3 years ago • 3 comments

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.

giacomoran avatar Jan 24 '23 19:01 giacomoran

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

777PolarFox777 avatar May 04 '23 10:05 777PolarFox777

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

pzkahoot avatar Sep 26 '23 09:09 pzkahoot

I opened #9423 to fix this: when a paste goes over the max length, $trimTextContentFromAnchor now keeps the part that fits instead of dropping the whole paste, and never cuts a grapheme in half.

— Ved Thakar

Vedthakar avatar Oct 21 '26 21:10 Vedthakar