mirror of https://github.com/fantasticit/think.git
close #208
parent
3e6e2f1daa
commit
3e954e655d
|
@ -1,4 +1,7 @@
|
||||||
|
import { getNodeType } from '@tiptap/core';
|
||||||
import { TaskList as BuiltInTaskList } from '@tiptap/extension-task-list';
|
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';
|
import { PARSE_HTML_PRIORITY_HIGHEST } from 'tiptap/core/constants';
|
||||||
|
|
||||||
export const TaskList = BuiltInTaskList.extend({
|
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;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue