Skip to content

Commit 2831462

Browse files
committed
fix(character-count): always provide the current editors doc
The `character-count` extensions storage is a singleton and might be initialized by other editors loaded at the same time. See ueberdosis/tiptap#6060 Signed-off-by: Max <max@nextcloud.com>
1 parent ab26032 commit 2831462

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/components/Menu/CharacterCount.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,17 @@ export default defineComponent({
5151
},
5252
methods: {
5353
refresh() {
54+
if (!this.editor) {
55+
this.wordCount = 0
56+
this.charCount = 0
57+
return
58+
}
59+
const { storage, state } = this.editor
5460
// characterCount is not reactive so we need this workaround
55-
this.wordCount = this.editor?.storage.characterCount.words()
56-
this.charCount = this.editor?.storage.characterCount.characters()
61+
// We also need to provide the doc as storage is a singleton in tiptap v2.
62+
// See ueberdosis/tiptap#6060
63+
this.wordCount = storage.characterCount.words(state.doc)
64+
this.charCount = storage.characterCount.characters(state.doc)
5765
},
5866
},
5967
})

0 commit comments

Comments
 (0)