Trigger InputRule on enter?

I was able to condense @bhl 's solution so that it can be added to what inputRules returns, that way you don’t have to duplicate the library code:

  const rplugin = inputRules({ rules: [/* ... your rules */] });

  const hkd = (view, event) => {
    if (event.key !== 'Enter') return false;
    const { $cursor } = view.state.selection;
    if ($cursor) return rplugin.props.handleTextInput(view, $cursor.pos, $cursor.pos, '\n');
    return false;
  };
  rplugin.props.handleKeyDown = hkd; // Add the handleKeyDown function

And yes, I also noticed this:

Thanks everyone for the help! It works perfectly!

2 Likes