Bring up context menu without selecting empty lines

I may have missed something obvious but curious about the behavior here.

When I right-click to bring up the context menu on an empty line, the line break is automatically selected, which also moves the caret to the next line:

This is from Safari but Edge works the same, I am using a Mac.

As a comparison, VS Code and TextEdit simply show the contextual menu, the caret position is not changed:

image

I understand this might be too minor, but it can sometimes be inconvenient because if I wanted to do something that inserts text into an empty line (for example, pasting text into the caret position), it deletes an extra line break.

Just curious, is there an easy to avoid this behavior?

Thanks for reading!

I’m not seeing this in Firefox or Chrome on Linux. I’ll try to test on a Mac when I have access to one.

Oh that’s interesting, thank you for the quick reply. I thought this was by design…

To add more details, for non-empty lines, if I place the caret at the end, it also selects the line break:

Can confirm that macOS browsers seem to do this. They do it in textarea and raw contenteditable elements too, so I guess it’s some kind of platform convention? It’d be messy (though probably possible) for CodeMirror to interfere here, and I’m not sure that’s the right call—if this is the expected behavior in such controls, it may be reasonable to align with that, even if VS Code doesn’t.

Thank you for confirming, Marijn!

Yeah I agree we’d rather not change if it’s something the system does. Pretty weird WebView does this while TextView (TextEdit.app) does the opposite, quite inconsistent, though.

I will take a look at the WebKit implementation at some point, thanks.