Skip to content

Conversation

@trinketmage
Copy link

@trinketmage trinketmage commented Oct 13, 2025

Changes Overview

Closes #5777
Instead of Node.textBetween(), if options.node is not set, uses this.editor.getText() to count full text from "descendant" nodes.

Implementation Approach

Using getText() seems to do getTextBetween() on node, as we need on the editor feat: add getText() and generateText() methods (fix #1428)

The key difference is that in current CharacterCount, options passed to node.textBetween() are options=undefined, then there is no options.textSerializers:

node.textBetween(0, node.content.size, undefined, ' ')

But inside getText(), options.textSerializers is defined through the schema, and, passed correctly to the getTextBetween():

  public getText(options?: { blockSeparator?: string; textSerializers?: Record<string, TextSerializer> }): string {
    const { blockSeparator = '\n\n', textSerializers = {} } = options || {}

    return getText(this.state.doc, {
      blockSeparator,
      textSerializers: {
        ...getTextSerializersFromSchema(this.schema),
        // here you get `mention` in case Mention extension is active
        ...textSerializers,
      },
    })
  }

Testing Done

Instead of counting 1 character for a "Mention", it now counts the current length with the prefix character that is by default @ and the actual length of the name by default in the example 12.

Verification Steps

Check those pages:
http://localhost:3000/src/Examples/Community/Vue/
http://localhost:3000/src/Examples/Community/React/

Add CharacterCount to this page:
http://localhost:3000/preview/Nodes/Mention

Additional Notes

Checklist

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Related Issues

#5777

@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2025

🦋 Changeset detected

Latest commit: bfc9589

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 70 packages
Name Type
@tiptap/extension-character-count Patch
@tiptap/core Patch
@tiptap/extension-blockquote Patch
@tiptap/extension-bold Patch
@tiptap/extension-bubble-menu Patch
@tiptap/extension-bullet-list Patch
@tiptap/extension-code-block-lowlight Patch
@tiptap/extension-code-block Patch
@tiptap/extension-code Patch
@tiptap/extension-collaboration-caret Patch
@tiptap/extension-collaboration Patch
@tiptap/extension-color Patch
@tiptap/extension-details Patch
@tiptap/extension-document Patch
@tiptap/extension-drag-handle-react Patch
@tiptap/extension-drag-handle-vue-2 Patch
@tiptap/extension-drag-handle-vue-3 Patch
@tiptap/extension-drag-handle Patch
@tiptap/extension-emoji Patch
@tiptap/extension-file-handler Patch
@tiptap/extension-floating-menu Patch
@tiptap/extension-font-family Patch
@tiptap/extension-hard-break Patch
@tiptap/extension-heading Patch
@tiptap/extension-highlight Patch
@tiptap/extension-horizontal-rule Patch
@tiptap/extension-image Patch
@tiptap/extension-invisible-characters Patch
@tiptap/extension-italic Patch
@tiptap/extension-link Patch
@tiptap/extension-list Patch
@tiptap/extension-mathematics Patch
@tiptap/extension-mention Patch
@tiptap/extension-node-range Patch
@tiptap/extension-ordered-list Patch
@tiptap/extension-paragraph Patch
@tiptap/extension-strike Patch
@tiptap/extension-subscript Patch
@tiptap/extension-superscript Patch
@tiptap/extension-table-of-contents Patch
@tiptap/extension-table Patch
@tiptap/extension-text-align Patch
@tiptap/extension-text-style Patch
@tiptap/extension-text Patch
@tiptap/extension-typography Patch
@tiptap/extension-underline Patch
@tiptap/extension-unique-id Patch
@tiptap/extension-youtube Patch
@tiptap/extensions Patch
@tiptap/html Patch
@tiptap/markdown Patch
@tiptap/pm Patch
@tiptap/react Patch
@tiptap/starter-kit Patch
@tiptap/static-renderer Patch
@tiptap/suggestion Patch
@tiptap/vue-2 Patch
@tiptap/vue-3 Patch
@tiptap/extension-dropcursor Patch
@tiptap/extension-focus Patch
@tiptap/extension-gapcursor Patch
@tiptap/extension-history Patch
@tiptap/extension-list-item Patch
@tiptap/extension-list-keymap Patch
@tiptap/extension-placeholder Patch
@tiptap/extension-table-cell Patch
@tiptap/extension-table-header Patch
@tiptap/extension-table-row Patch
@tiptap/extension-task-item Patch
@tiptap/extension-task-list Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Oct 13, 2025

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit bfc9589
🔍 Latest deploy log https://app.netlify.com/projects/tiptap-embed/deploys/690362e2c7a7f300082fbc53
😎 Deploy Preview https://deploy-preview-7071--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@trinketmage trinketmage marked this pull request as ready for review October 13, 2025 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Character Count extension does not count characters correctly when there is mention

1 participant