Skip to content

Commit

Permalink
Don't assume nodeDOM returns non-null
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marijnh committed Oct 25, 2022
1 parent f833ff0 commit 5a82a98
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/dropcursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5a82a98

Please sign in to comment.