Partial Enter KeyDown Event by ProseMirror on mobile?

On mobile (Android) our commands weren’t working that were mapped to Enter button and sometimes resulted in weird behaviours. We did some remote debugging on Android.

We discovered that on Android, for each KeyDown, we get events with key as Unidentified but when Enter is pressed ProseMirror detects this and dispatches another KeyDown event with the correct key property, Enter.

However this is insufficient, apparently this event has a empty code property and hence does not trigger commands attached to the keymaps.

So we created a that plugin listens for this “incomplete” Enter KeyDown event, and dispatches a new event with the code property set as Enter, which triggers our commands.

The event with the empty code property is a bug or are we missing something?

Our plugin:

export const mobileEventHandlerPlugin = new Plugin({
  props: {
    handleDOMEvents: {
      keydown(view, event) {
        if (!isAndroid) return false;
        if (event.key === "Enter" && event.code.length === 0) {
          event.preventDefault();
          event.stopPropagation();
          view.dispatchEvent(
            new KeyboardEvent("keydown", {
              repeat: event.repeat,
              altKey: event.altKey,
              shiftKey: event.shiftKey,
              composed: event.composed,
              ctrlKey: event.ctrlKey,
              key: "Enter",
              code: "Enter",
            }),
          );
        }
      },
    },
  },
});

Video: https://youtu.be/B0rAH6zVMwQ

  • I press Enter. I get two events:
      1. Unidentified Event.
      1. Partial KeyDown Enter Event.
  • Our inputBr command does not work (attached to Enter).
  • I enable the plugin and press Enter. I get three events.
      1. Unidentified Event.
      1. Partial KeyDown Enter Event.
      1. Previous event caught and new event thrown with code property set to Enter.
  • Our inputBr command does works (attached to Enter).

That is odd. The code that creates these events does set a code property, and when I test it I see that holding a non-empty string.