Hi Marijn & CodeMirror team, Thanks for the great editor!
Currently, I use domEventHandlers
to handle the drop event, as shown below:
EditorView.domEventHandlers({
drop() {
// upload images
}
});
According to the documentation, these event handlers are registered on the content element. However, my specific requirement is to register the event handler on the scroll element, allowing the entire scrollable area to accept and handle dropped images.
Here’s the approach I’m currently using to achieve this:
view.scrollDOM.addEventListener('drop', (event) => {
event.preventDefault()
event.stopPropagation()
if (event.target !== view.scrollDOM) return
view.contentDOM.dispatchEvent(new DragEvent('drop', event))
})
This method involves delegating the drop
event from the scrollDOM
to the contentDOM
, and it’s been working well so far. However, I was wondering if there might be a better way to do it.
Thanks!