Handle after handleKeyDown state change

Hey folks,

I’m looking to create a plugin that will prevent the user from using the arrow keys to move the caret inside of certain marks. aka If I arrow “up” into a mark, the caret should be moved to the beginning of the mark.

The problem I’m having is that the state.selection in handleKeyDown is the selection prior to the key event being handled by Prosemirror. What is the best way to recreate an “after” hook so that I can check the state once the arrow key event has been applied to the selection?

Maybe appendTransaction can help here. There’s no real way to figure out what cursor motion is going to happen before it has actually happened (as in, has been created as a transaction).

1 Like