From ea7dab68aeda03cdce4a773342a7dc3b94283a7a Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 11 Dec 2023 23:58:46 +0100 Subject: [PATCH] fix(editor): add workaround for checklist tiptap bug --- src/components/input/editor/TipTap.vue | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/components/input/editor/TipTap.vue b/src/components/input/editor/TipTap.vue index 4b532013d..7a967d1f7 100644 --- a/src/components/input/editor/TipTap.vue +++ b/src/components/input/editor/TipTap.vue @@ -200,7 +200,9 @@ const CustomTableCell = TableCell.extend({ }) type CacheKey = `${ITask['id']}-${IAttachment['id']}` -const loadedAttachments = ref<{ [key: CacheKey]: string }>({}) +const loadedAttachments = ref<{ + [key: CacheKey]: string +}>({}) const CustomImage = Image.extend({ addAttributes() { @@ -356,13 +358,28 @@ const editor = useEditor({ TaskItem.configure({ nested: true, onReadOnlyChecked: (node: Node, checked: boolean): boolean => { - if (isEditEnabled) { - node.attrs.checked = checked - bubbleSave() - return true + if (!isEditEnabled) { + return false } - return false + // The following is a workaround for this bug: + // https://github.com/ueberdosis/tiptap/issues/4521 + // https://github.com/ueberdosis/tiptap/issues/3676 + + editor.value!.state.doc.descendants((subnode, pos) => { + if (node.eq(subnode)) { + const {tr} = editor.value!.state + tr.setNodeMarkup(pos, undefined, { + ...node.attrs, + checked, + }) + editor.value!.view.dispatch(tr) + bubbleSave() + } + }) + + + return true }, }),