Plugin handleKeyDown, no event fired on Enter key press

I’m building autocompletion on top of prosemirror-suggestions, things work relatively fine but the only issue I’m having is that the Enter key is not passed to the handleKeyDown event.

The definition of handleKeyDown in prosemirror-suggestions is:

handleKeyDown: function handleKeyDown(view, event) {
    var _getState = this.getState(view.state),
        active = _getState.active;

    if (!active) return false;

    return onKeyDown({ view: view, event: event });
  },

As I’m pretty new to prosemirror I have inserted a console.log call at the start of the function definition, just to be sure that the issue wasn’t because of the getState.active variable.

I’d appreciate a few pointers on how I could capture the Enter key, as I want to use it as the autocompletion selection event; while also preventing the insertion of a newline during autocompletion.

1 Like

Could there be another plugin with higher precedence handling the key?

My entire setup is based around the example editor from the official website + the example setup provided in the prosemirror-suggestions plugin repository README.

Unless the example editor captures the enter key press event there should be no other plugin configured.

I’ll try to dig into the source code and try to debug the issue.

It does—enter is bound to its default behavior by the base keymap, and if your plugin comes after that in the configuration, you’ll only get a chance if none of the default commands apply.

Thank you, I have included my suggestion plugin before the example plugins and it works just fine now. It just happened that I came back to this thread to report the same finding :slight_smile:

At least now through the debugging session I have a better understanding of the how keymapping is handled.

1 Like