Skip to content

Commit

Permalink
fix: improve drag position for node views
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed Apr 8, 2021
1 parent 992986b commit 5e5b8db
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/core/src/NodeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ export class NodeView<Component, Editor extends CoreEditor = CoreEditor> impleme
return
}

const domBox = this.dom.getBoundingClientRect()
const handleBox = target.getBoundingClientRect()
const x = handleBox.x - domBox.x
const y = handleBox.y - domBox.y

// sometimes `event.target` is not the `dom` element
event.dataTransfer?.setDragImage(this.dom, 0, 0)
event.dataTransfer?.setDragImage(this.dom, x, y)

const selection = NodeSelection.create(view.state.doc, this.getPos())
const transaction = view.state.tr.setSelection(selection)
Expand Down

0 comments on commit 5e5b8db

Please sign in to comment.