Skip to content

Commit

Permalink
Allows custom predicate function as option
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesthomsondev authored Jul 9, 2021
1 parent 0310dbb commit 7cc623f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/dropcursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DropCursorView {
this.width = options.width || 1
this.color = options.color || "black"
this.class = options.class
this.predicate = options.predicate || function () { return true }
this.cursorPos = null
this.element = null
this.timeout = null
Expand Down Expand Up @@ -108,10 +109,8 @@ class DropCursorView {
if (!this.editorView.editable) return
let pos = this.editorView.posAtCoords({left: event.clientX, top: event.clientY})

// Disables dropcursor when Node disableDropCursor property is true
// and is not a draggable Node within the document
const node = this.editorView.state.doc.nodeAt(pos.pos);
if (node && node.type.spec.disableDropCursor && !this.editorView.dragging) return;
const node = this.editorView.state.doc.nodeAt(pos.inside === -1 ? pos.pos : pos.inside)
if (node && node.type.spec.disableDropCursor && this.predicate()) return

if (pos) {
let target = pos.pos
Expand Down

0 comments on commit 7cc623f

Please sign in to comment.