-
-
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 counts non-existing characters #1049
Comments
A quick fix to this would maybe be to replace |
Thanks for chiming in @BrianHung! Both use cases are probably relevant, for example this is Twitter (they should know how to count characters): |
Thanks for the quick responses. I believe the Twitter example is very sensible. End-users can intuitively understand that a newline counts as a character (they're making a typing action). Maybe count +0 can feel unnatural from that perspective. The same goes for creating List Items, which are currently counted as +4. I'm thinking the HTML elements are miscounted (lists require two elements |
Your intuition is close but off by a multiplier of 2 -- lists uses 4 instead of 2, paragraphs uses 2 instead of 1 -- because each nested semantic element needs a start and an end position, e.g. for a list, you will have I'm not sure if there's a universal way to count text characters, but implementing custom behavior is simple and involves recursively descending on the doc to count the number of |
Maybe we could add an option |
This is used in the Editor too, so that would require us to add the ability to register helper functions through extensions. 👀 https://github.com/ueberdosis/tiptap-next/blob/main/packages/core/src/Editor.ts#L426 |
…#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>
What happens?
CharacterCount extension counts non-existing characters.
An empty editor with CharacterCount enabled will show +2 for every newline, and + 4 for every list; even though there are no characters. When adding characters, the count increments on top of those non-existing counted characters.
I haven't tested "Code" and "CodeBlock", but I expect a similar result.
Steps to reproduce the behavior:
Create a new Codesandbox replicating your error
Try in the documentation editor: https://next.tiptap.dev/api/extensions/character-count/
What behavior did you expect?
Count +0 on newlines and lists.
What’s your environment?
Anything else?
I haven't tested "Code" and "CodeBlock", but I expect a similar result.
The text was updated successfully, but these errors were encountered: