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
- ProseMirror doesn’t bind to these shortcuts.
- This issue only occurs on Safari and Chrome. Firefox works fine without any issue.
- 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 toctrl-a
/ctrl-e
inmacBaseKeymap
?
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