This commit is contained in:
fantasticit 2022-11-25 15:21:10 +08:00
parent 3e6e2f1daa
commit 3e954e655d
1 changed files with 22 additions and 0 deletions

View File

@ -1,4 +1,7 @@
import { getNodeType } from '@tiptap/core';
import { TaskList as BuiltInTaskList } from '@tiptap/extension-task-list';
import { liftListItem } from 'prosemirror-schema-list';
import { findParentNodeClosestToPos } from 'prosemirror-utils';
import { PARSE_HTML_PRIORITY_HIGHEST } from 'tiptap/core/constants';
export const TaskList = BuiltInTaskList.extend({
@ -10,4 +13,23 @@ export const TaskList = BuiltInTaskList.extend({
},
];
},
addKeyboardShortcuts() {
return {
...this.parent?.(),
Backspace: ({ editor }) => {
const { selection } = editor.state;
const { $from } = selection;
const maybeTask = findParentNodeClosestToPos($from, (node) => node.type.name === this.name);
if (maybeTask && maybeTask.node.childCount === 1 && !maybeTask.node.textContent) {
const name = this.editor.can().liftListItem('taskItem') ? 'taskItem' : 'listItem';
const type = getNodeType(name, editor.view.state.schema);
return liftListItem(type)(editor.view.state, editor.view.dispatch);
}
return false;
},
};
},
});