-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CharacterCount.limit
does not match getCharacterCount()
or state.doc.content.size
#1839
Comments
Also seeing this, my limit is set to 5000, but the actual count always goes up to 5002. Two characters seem to be getting lost somewhere. As a very crude hide-a-bug "solution" which should go unnoticed to users due to a high limit I'm rendering the count as: But this needs real fixing. |
The In @stefan-schweiger demo content:
Before starting to count its character, we should notice the And below is the
https://github.com/ueberdosis/tiptap/blob/main/packages/core/src/Editor.ts#L447-L449 And I found the
If you call it like this: |
How about adding these three options to this extension: {
countThroughSerializer: boolean, // default: false
blockSeparator: string // default: '\n\n'
textSerializers: Record<string, TextSerializer>,
}
|
But the above change, still can't provide the counting number to show, I guess it has to write the number in |
I have added a pr for this problem. Below code is how to enable it:
Here is a new way to get the character number of this extension counting:
Welcome to any discussion and suggestions and hope this change would be helpful. 🙂 |
…#1049, fix #1550, fix #1839, fix #2245 * fix a bug when exceeding the character limit * find a better way to limit the doc size * check paste events * add storage method * refactoring * use textBetween instead of textContent * return early if no limit is set * add words method to storage * show word count in charactercount demo Co-authored-by: Philipp Kühn <philippkuehn@MacBook-Pro-von-Philipp.local>
Description
When the content of the editor contains something like a list the set limit for
CharacterCount
does not match any properties returned from the editor.For example:
![image](https://user-images.githubusercontent.com/3532342/131989556-537f0808-6265-4f2e-922a-80a5f51846ce.png)
The limit is set to 20, but
getCharacterCount()
returns 22 andstate.doc.content.size
returns 24.While I would expect the actual count to be 15 (chars + new line), I think at least the CharacterCount extension should match the limit to
getCharacterCount
. I've looked into the source code and it seems like the extension usesstate.doc.content.size
but for whatever reason the result is even more off.CodeSandbox
I created a CodeSandbox to help you debug the issue:
The text was updated successfully, but these errors were encountered: