How to handle drag-n-drop or paste events

Hello! I could not figure out how to create callback for paste or drag-n-drop events in CodeMirror 6.
I’m trying to handle image paste event. For now I’m using
window.addEventListener('drop', (event: DragEvent) => {}) and
window.addEventListener('paste', (event: ClipboardEvent) => {}).
Thanks in advance!

You can use the domEventHandlers facet to register such handlers. I.e. add something like this to your extensions:

  EditorView.domEventHandlers.of({
    drop(event, view) { ... },
    paste(event, view) { ... }
  })
1 Like