Shortcut Ctrl-A / Ctrl-E don't work on macOS with inline node

There are two pairs of shortcuts that can move the cursor to the start/end of the current line.

Mac keyboard shortcuts - Apple Support

  • Command–Left Arrow: Move the insertion point to the beginning of the current line.
  • Command–Right Arrow: Move the insertion point to the end of the current line.

  • Control-A: Move to the beginning of the line or paragraph.
  • Control-E: Move to the end of a line or paragraph.

They have a subtle difference when the paragraph has multiple lines, but that’s nothing to do with the following issue.

When you have a contenteditable="false" inline node inside your paragraph, Cmd-Left/Right works well but Ctrl-A/E will be stuck at the boundary of the inline node.

I don’t think ProseMirror has anything to do with this issue, because

  1. ProseMirror doesn’t bind to these shortcuts.
  2. This issue only occurs on Safari and Chrome. Firefox works fine without any issue.
  3. I can reproduce it with a simple HTML that contains an editable div.
<body>
    <div id="root" contenteditable="true">
        <p>Just plain HTML: <a class="inline-node" tabindex="-1" contenteditable="false">#tag</a> hello</p>
    </div>
    <style>
        .inline-node {
            color: red;
        }
    </style>
</body>

I haven’t been able to find much discussion on this issue. The only thing I can find is a post from 4 years ago.

Some navigational bindings do not quite as expected, for instance Ctrl-e / Ctrl-a jumps to the next / previous code_inline node instead of end / beginning of the line.

I tried to add keymap and handle Ctrl-A/E with ProseMirror. It seems to works. So I guess I’ve found a workaround for this issue.

Here are some follow-up questions about this issue:

  • Any better suggestions for this issue?
  • Is it a good idea for me to submit a PR to prosemirror-commands and add bindings to ctrl-a/ctrl-e in macBaseKeymap?

Ps, here is my test environment and result for this issue:

  • macOS 11.6.2
    • Chrome 97.0: has issue
    • Safari 15.2: has issue
    • Firefox 96.0: no issue
  • iPadOS 15.2:
    • Chrome 96.0: no issue
    • Safari: no issue
    • Firefox 40.2: no issue

The library currently doesn’t handle ctrl-a/e (or home/end), letting the browser do its native thing. So this would be a browser bug.

I agree this is a browser bug. Do you thing it’s a good idea to add coding as workaround for this browser bug in prosemirror-command package? I can submit a PR if you want.

Yeah, sorry, you said all I replied already in your original post. I’m a bit hesitant to add more custom key handling, because invariably that will then result in bug reports because the custom handling disagrees with native behavior in subtle ways. But I guess moving to the start/end of the textblock (and returning false when not in a textblock) is likely to be mostly unproblematic. I’d be interested in such a PR, and I guess it should bind home/end on non-macOS platforms as well.

I’ve submit the pull request: Bind Ctrl-a and Ctrl-e on macOS by ocavue · Pull Request #13 · ProseMirror/prosemirror-commands · GitHub

I didn’t bind home/end as I only see this bug on macOS.

1 Like

You may want to implement shift versions as well then so the extend selection behavior is consistent.