Dragging whole Paragraphs leaves empty Paragraph

Hey, I’m working on a project where I want to remove a paragraph if the whole content has been selected and moved (eg drag&drop).

Currently an empty paragraph, with the standard break for later editing, remains but I want it gone too. I wrote a plugin for that which works for all but one case: moving the node to the end

handleDrop: (view: EditorView, _event: DragEvent, slice: Slice, moved: boolean) => {
                    if (!moved) return false;
                    const {
                        selection: { from, to },
                        doc,
                        tr,
                    } = view.state;
                    const first = doc.resolve(from).node();
                    const last = doc.resolve(to).node();
                    const firstMovedNode = slice.content.child(0);
                    const lastMovedNode = slice.content.child(slice.content.childCount - 1);
                    if (first.nodeSize === firstMovedNode.nodeSize && last.nodeSize === lastMovedNode.nodeSize) {
                        /*
                            we know:
                            - it's a move
                            - the first and last nodes are the same size
                                -> may be the same if only 1 node is moved

                            => we assume whole nodes have been moved
                         */
                        view.dispatch(tr.delete(from - 1, to + 1));
                    }
                    return false;
                },

when moving to the doc end I get an OutOfRange Error. Most likely because of the tr.delete which somehow gets handled before the drop-handler is done. Thus the drop position does not exist anymore.

Is there an easier way to have the whole paragraph removed automagically via schema magic?

Greetings

When handleDrop returns false it is assumed to not have messed with the editor state. You’ll need to handle the insertion as well and return true from the handler.