Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-crabs-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tiptap/extension-character-count': patch
---

Update `CharacterCount` to take into account `schema` passed from extensions to count descendant `node` characters such as `Mention`
8 changes: 4 additions & 4 deletions demos/src/Examples/Community/React/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ context('/src/Examples/Community/React/', () => {
})

it('should count the characters correctly', () => {
// check if count text is "44 / 280 characters"
cy.get('.character-count').should('contain', '44 / 280 characters')
// check if count text is "56 / 280 characters"
cy.get('.character-count').should('contain', '56 / 280 characters')

// type in .tiptap
cy.get('.tiptap').type(' Hello World')
cy.get('.character-count').should('contain', '56 / 280 characters')
cy.get('.character-count').should('contain', '68 / 280 characters')

// remove content from .tiptap and enter text
cy.get('.tiptap').type('{selectall}{backspace}Hello World')
Expand All @@ -32,7 +32,7 @@ context('/src/Examples/Community/React/', () => {

// check if the user is mentioned
cy.get('.tiptap').should('have.text', `@${name} `)
cy.get('.character-count').should('contain', '2 / 280 characters')
cy.get('.character-count').should('contain', '14 / 280 characters')
})
})
})
8 changes: 4 additions & 4 deletions demos/src/Examples/Community/Vue/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ context('/src/Examples/Community/Vue/', () => {
})

it('should count the characters correctly', () => {
// check if count text is "44 / 280 characters"
cy.get('.character-count').should('contain', '44 / 280 characters')
// check if count text is "56 / 280 characters"
cy.get('.character-count').should('contain', '56 / 280 characters')

// type in .tiptap
cy.get('.tiptap').type(' Hello World')
cy.get('.character-count').should('contain', '56 / 280 characters')
cy.get('.character-count').should('contain', '68 / 280 characters')

// remove content from .tiptap and enter text
cy.get('.tiptap').type('{selectall}{backspace}Hello World')
Expand All @@ -32,7 +32,7 @@ context('/src/Examples/Community/Vue/', () => {

// check if the user is mentioned
cy.get('.tiptap').should('have.text', `@${name} `)
cy.get('.character-count').should('contain', '2 / 280 characters')
cy.get('.character-count').should('contain', '14 / 280 characters')
})
})
})
2 changes: 1 addition & 1 deletion packages/extensions/src/character-count/character-count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const CharacterCount = Extension.create<CharacterCountOptions, CharacterC
const mode = options?.mode || this.options.mode

if (mode === 'textSize') {
const text = node.textBetween(0, node.content.size, undefined, ' ')
const text = options?.node ? node.textBetween(0, node.content.size, undefined, ' ') : this.editor.getText()

return this.options.textCounter(text)
}
Expand Down