Larger cursor size on empty line

The cursor size on an empty line is the full height of the line, but is just the height of the text on a non-empty line. This is much more obvious when using larger line heights. Example:

It would be good if these were consistent. Whether it’s the full line height or the text height seems be a matter of taste; VS Code and Ace go for full line height, JetBrains goes for text height, Sublime seems to go for text-height-plus-a-bit. For CM6, with potentially different line heights depending on widgets etc., I imagine text height makes more sense in general.

This seems to be a Firefox-specific problem. Chrome returns a rectangle matching the text height for a <br> element, but Firefox gives it the height of the entire line for some reason. Unfortunately, JavaScript APIs do not give you a way to directly query the text size in a given element, and for empty lines we only have a <div><br></div> structure.

Adding extra elements to enable this kind of measuring seems invasive (and likely to cause new editing weirdness). Basing the height of the cursor on that of text on other lines might be a workaround, but somewhat involved, and also not be very reliable (there may be no lines with text, and the line might have been styled to have a different font size) so I’m not quite sure yet how to proceed here.

This patch should work around the issue in most cases (though it still won’t work for empty lines with a font size that differs from the rest of the document).

1 Like

Looks good to me. Thanks.