tiptap: remove drag handler in nested paragraph

This commit is contained in:
fantasticit 2022-08-17 16:36:01 +08:00
parent 57774553e0
commit e08e72e1ae
1 changed files with 20 additions and 1 deletions

View File

@ -2,7 +2,7 @@ import { Extension } from '@tiptap/core';
import { Plugin, PluginKey, Selection } from 'prosemirror-state'; import { Plugin, PluginKey, Selection } from 'prosemirror-state';
import { NodeSelection } from 'prosemirror-state'; import { NodeSelection } from 'prosemirror-state';
import { __serializeForClipboard, EditorView } from 'prosemirror-view'; import { __serializeForClipboard, EditorView } from 'prosemirror-view';
import { ActiveNode, removePossibleTable, selectRootNodeByDom } from 'tiptap/prose-utils'; import { ActiveNode, getNodeAtPos, removePossibleTable, selectRootNodeByDom } from 'tiptap/prose-utils';
export const DragablePluginKey = new PluginKey('dragable'); export const DragablePluginKey = new PluginKey('dragable');
@ -164,6 +164,7 @@ export const Dragable = Extension.create({
result.node.type.name === 'doc' || result.node.type.name === 'doc' ||
result.node.type.name === 'title' || result.node.type.name === 'title' ||
result.node.type.name === 'tableOfContents' || result.node.type.name === 'tableOfContents' ||
result.node.type.name === 'column' ||
// empty paragraph // empty paragraph
(result.node.type.name === 'paragraph' && result.node.nodeSize === 2) (result.node.type.name === 'paragraph' && result.node.nodeSize === 2)
) { ) {
@ -172,6 +173,24 @@ export const Dragable = Extension.create({
return false; return false;
} }
/**
* paragraph
*/
if (result.node.type.name === 'paragraph') {
const { $from, to } = view.state.selection;
const same = $from.sharedDepth(to);
if (same != 0) {
const pos = $from.before(same);
const parent = getNodeAtPos(view.state, pos);
if (parent && parent.type.name !== 'paragraph') {
if (dragging) return false;
hideDragHandleDOM();
return false;
}
}
}
activeNode = result; activeNode = result;
renderDragHandleDOM(view, result.el); renderDragHandleDOM(view, result.el);