fix: character count to work properly on editor rerenders and read only mode (#5554)
* fix: character count to work properly on editor rerenders and read only mode * fix: desctructing properly at the start
This commit is contained in:
parent
7c3fc690e9
commit
4d38a10f8b
5 changed files with 21 additions and 13 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import CharacterCount from "@tiptap/extension-character-count";
|
||||
import TaskItem from "@tiptap/extension-task-item";
|
||||
import TaskList from "@tiptap/extension-task-list";
|
||||
import TextStyle from "@tiptap/extension-text-style";
|
||||
|
|
@ -104,4 +105,5 @@ export const CoreReadOnlyEditorExtensions = (mentionConfig: {
|
|||
mentionHighlights: mentionConfig.mentionHighlights,
|
||||
readonly: true,
|
||||
}),
|
||||
CharacterCount,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -230,10 +230,12 @@ export const useEditor = (props: CustomEditorProps) => {
|
|||
editor.chain().focus().deleteRange({ from, to }).insertContent(contentHTML).run();
|
||||
}
|
||||
},
|
||||
documentInfo: {
|
||||
characters: editorRef.current?.storage?.characterCount?.characters?.() ?? 0,
|
||||
paragraphs: getParagraphCount(editorRef.current?.state),
|
||||
words: editorRef.current?.storage?.characterCount?.words?.() ?? 0,
|
||||
getDocumentInfo: () => {
|
||||
return {
|
||||
characters: editorRef?.current?.storage?.characterCount?.characters?.() ?? 0,
|
||||
paragraphs: getParagraphCount(editorRef?.current?.state),
|
||||
words: editorRef?.current?.storage?.characterCount?.words?.() ?? 0,
|
||||
};
|
||||
},
|
||||
}),
|
||||
[editorRef, savedSelection, fileHandler.upload]
|
||||
|
|
|
|||
|
|
@ -82,10 +82,12 @@ export const useReadOnlyEditor = ({
|
|||
if (!editorRef.current) return;
|
||||
scrollSummary(editorRef.current, marking);
|
||||
},
|
||||
documentInfo: {
|
||||
characters: editorRef.current?.storage?.characterCount?.characters?.() ?? 0,
|
||||
paragraphs: getParagraphCount(editorRef.current?.state),
|
||||
words: editorRef.current?.storage?.characterCount?.words?.() ?? 0,
|
||||
getDocumentInfo: () => {
|
||||
return {
|
||||
characters: editorRef?.current?.storage?.characterCount?.characters?.() ?? 0,
|
||||
paragraphs: getParagraphCount(editorRef?.current?.state),
|
||||
words: editorRef?.current?.storage?.characterCount?.words?.() ?? 0,
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export type EditorReadOnlyRefApi = {
|
|||
clearEditor: (emitUpdate?: boolean) => void;
|
||||
setEditorValue: (content: string) => void;
|
||||
scrollSummary: (marking: IMarking) => void;
|
||||
documentInfo: {
|
||||
getDocumentInfo: () => {
|
||||
characters: number;
|
||||
paragraphs: number;
|
||||
words: number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue