ueberdosis / tiptap

The headless rich text editor framework for web artisans.
https://tiptap.dev
MIT License
27.8k stars 2.31k forks source link

[Bug]: Pasting formatted content over the CharacterCount limit doesn't seem to work - content left blank #4820

Open tobewisebeforeiamold opened 10 months ago

tobewisebeforeiamold commented 10 months ago

Which packages did you experience the bug in?

CharacterCount, react

What Tiptap version are you using?

2.1.15

What’s the bug you are facing?

When using CharacterCount.configure({ limit: 240 }) and attempting to paste in more than 240 characters that is not unformatted text from the clipboard, the input remains empty.

I can reproduce this in the "Usage" example on at the bottom of https://tiptap.dev/docs/editor/api/extensions/character-count#usage.

This page (https://tiptap.dev/blog/release-notes/new-character-count-extension) seems to indicate that this copy/paste behavior is a bug.

To Reproduce

  1. Visit https://tiptap.dev/blog/release-notes/new-character-count-extension and select all of the paragraphs and ordered list from that page and copy it to your clipboard
  2. Then visit https://tiptap.dev/docs/editor/api/extensions/character-count and scroll down to the "Usage" section
  3. Paste in the text you copied into your clipboard into that example - see that the copy does not change; that the pasted content is rejected

What browser are you using?

Firefox

Code example

https://tiptap.dev/docs/editor/api/extensions/character-count#usage

What did you expect to happen?

If I configure CharacterCount to use a limit of 240 characters, and I paste in 250 characters, even if it's formatted, I would expect to see 240 of those 250 characters

Anything to add? (optional)

No response

Did you update your dependencies?

Are you sponsoring us?

xavivars commented 8 months ago

I'm facing this same problem. It's a bug in this part of the code:

https://github.com/ueberdosis/tiptap/blob/main/packages/extension-character-count/src/character-count.ts#L115C10-L119C81

In my case, I'm not pasting any complex node: I'm literally pasting a long text file that contains no format at all: it's coming with a .txt file with a lot of lines (which become paragraphs). In my case, tr.doc.content.size is 22730, while newSize is being calculated as 21516 (I'm working with a limit of 10000).

After deleting the amount of characters that are supposed to be over (11516), the remaining size is 10664.

To be honest, the behavior is pretty unintuitive.

tsl1127 commented 7 months ago

i have the same problem(when i use insertContent with many nodes at once);It would be best if it can be intercepted automatically