From 5a82a98663341bd0176c7d3779cc066a775e96f1 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 25 Oct 2022 17:32:59 +0200 Subject: [PATCH] Don't assume nodeDOM returns non-null FIX: Fix a crash when there's no DOM for the node next to the drag position. See https://discuss.prosemirror.net/t/dropcursor-bug-with-nodeviews/4977 --- src/dropcursor.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dropcursor.ts b/src/dropcursor.ts index 0a10486..30a9d5f 100644 --- a/src/dropcursor.ts +++ b/src/dropcursor.ts @@ -75,12 +75,14 @@ class DropCursorView { if (!$pos.parent.inlineContent) { let before = $pos.nodeBefore, after = $pos.nodeAfter if (before || after) { - let nodeRect = (this.editorView.nodeDOM(this.cursorPos! - (before ? before.nodeSize : 0)) as HTMLElement) - .getBoundingClientRect() - let top = before ? nodeRect.bottom : nodeRect.top - if (before && after) - top = (top + (this.editorView.nodeDOM(this.cursorPos!) as HTMLElement).getBoundingClientRect().top) / 2 - rect = {left: nodeRect.left, right: nodeRect.right, top: top - this.width / 2, bottom: top + this.width / 2} + let node = this.editorView.nodeDOM(this.cursorPos! - (before ? before.nodeSize : 0)) + if (node) { + let nodeRect = (node as HTMLElement).getBoundingClientRect() + let top = before ? nodeRect.bottom : nodeRect.top + if (before && after) + top = (top + (this.editorView.nodeDOM(this.cursorPos!) as HTMLElement).getBoundingClientRect().top) / 2 + rect = {left: nodeRect.left, right: nodeRect.right, top: top - this.width / 2, bottom: top + this.width / 2} + } } } if (!rect) {