Stop propagating events handled by core prose-mirror packages


Is it possible to stopEvent propagation for keys handled by prosemirror core packages like baseKeymap, gapCursor and etc.? I can think of adding them all to if statement inside handleKeyDown but that doesn’t feel right

My use case: I want to handle ArrowUp and ArrowDown key presses on parent div when they were not handled by ProseMirror

Thank you

Does checking for event.defaultPrevented not work?

Nope. It equals false.

As for now I do smth like this in EditorView constructor:

handleKeyDown(e) {
  if (['ArrowUp', 'ArrowDown'].includes(e.key)) {

ProseMirror will call preventDefault() on the keydown event for keys that it handles (where the DOM event handler of command bound via a keymap returns true), and those handlers should run before outer elements get the event, so I’m pretty usre defaultPrevented should be true for handled keys.

And how keys like ‘ArrowUp’,’‘ArrowDown’,’‘ArrowLeft’,’‘ArrowRight’ are handled? Can’t find their handlers in baseKeymap. Do they have any handlers in prosemirror or the browser itself if responsible for cursor navigation? I think it can be the reason why defaultPrevented equals to false

Those aren’t handled, at all, since the library depends on the browser’s native behavior going through.