Determine Which Key Was Pressed

#1

Is there a way to determine which key was pressed that caused a transaction to be passed to the dispatcher?

I can’t see anything obvious - and so figure I might have to hook into the base key mappings to get that event, but figured I’d ask in case this is being passed around and I’m not spotting it.

Unless I’m thinking about this in completely the wrong way (likely)…is there a wildcard way of binding to all keys?

That way I could fire a key event, and cancel (return false) if needed within the command before any other registered commands are invoked.

I can only see a way of binding to explicit key combinations in [prosemirror-keymap] keymap or keydownHandler

Thanks

0 Likes

#2

Transactions don’t carry information about what key triggered them, no. I’d argue that they don’t need to—at that level, you’re working with state updates, not UI events anymore. If you need to add semantic information to a transaction, the command that a key is bound to can use the metadata mechanism for that.

0 Likes

#3

Great - thanks @marijn

0 Likes