This commit is contained in:
Nick Sellen 2025-06-04 23:13:45 +02:00 committed by GitHub
commit b820acf2af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -149,7 +149,7 @@ export const TaskItem = Node.create<TaskItemOptions>({
const { checked } = event.target as any
if (editor.isEditable && typeof getPos === 'function') {
if (typeof getPos === 'function') {
editor
.chain()
.focus(undefined, { scrollIntoView: false })
@ -161,6 +161,14 @@ export const TaskItem = Node.create<TaskItemOptions>({
}
const currentNode = tr.doc.nodeAt(position)
if (!editor.isEditable && this.options.onReadOnlyChecked) {
// Reset state if onReadOnlyChecked returns false
if (!currentNode || !this.options.onReadOnlyChecked(currentNode, checked)) {
checkbox.checked = !checkbox.checked
return false
}
}
tr.setNodeMarkup(position, undefined, {
...currentNode?.attrs,
checked,
@ -170,12 +178,6 @@ export const TaskItem = Node.create<TaskItemOptions>({
})
.run()
}
if (!editor.isEditable && this.options.onReadOnlyChecked) {
// Reset state if onReadOnlyChecked returns false
if (!this.options.onReadOnlyChecked(node, checked)) {
checkbox.checked = !checkbox.checked
}
}
})
Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {