Closed smingerson closed 2 years ago
I've seen something similar before (so I know what you mean) but I can't repro his particular issue. I'm using the same version of RStudio on Mac and get these results:
Start of line:
End of line:
Function calls:
What font are you using? I think the problem may be that you're using a font with a bold face that's wider than the normal face. I tried a few fonts to see if I could repro the issue that way, but they all behaved as expected (Courier, Andale Mono, Fira Code, Hasklig, Monaco). Or maybe it's a Windows thing?
Ah, I hadn't considered it being Windows-specific, but it would not surprise me. It happens with Fira Code on Windows, along with Courier, Courier New and Cascadia Mono.
Here's some screenshots, all with the cursor positioned at end of line. Courier font
Yeah the bold font glyphs are clearly wider than their normal font weight counterparts in those lines. Can you try something for me just to see what happens? Under Global Options > General > Advanced > OS Integration ... if you have similar options on Windows does the behavior change with any of them (and what's your current setting)?
I had it set to auto-detect. Unfortunately, behavior remains the same under all choices, which are the same as those listed for you.
I've also had this issue and tried to investigate it through - it seems there is no universal fix for this, because it lies deeply in how ACE editor (which RStudio uses) works. It calculates fontmetrics once, and uses them everywhere. So it can only work with only one monospaced font. You can try to reproduce this issue on live demo at ACE website https://ace.c9.io, by changing e.g. fontfamily for comments or function calls.
However, there is a workaround - you have to use a font, that has a native bold version installed on the system. Say you use Fira Code, it comes with Regular, Light, Medium, Bold, SemiBold and Retina versions. If you use "Regular" version (labelled Fira Code in RStudio), there will be a Bold variant associated with it, and it will work fine - since authors of Fira Code made sure different versions have the same character width. But, if you use "Retina" or "SemiBold" - there is now no "Bold" variant for those, so WebKit simulates them for you. This leads to different character widths between your base and bold variants.
TL;DR Install a font with native Bold version, that has the same character width as Regular, and use the Regular version.
Thanks for the advice and thorough explanation @Darxor!
I had 2 versions each of Fira Code font face installed. I uninstalled them all, and re-installed the most recent version -- now it's working as expected. Thanks for the explanation @Darxor, which led me to take another look!
Themes which increase the font-weight of certain elements, such as a11y-dark (and light, I assume), lead to cursor shifting in lines which contain such elements. This is maybe more of a problem with RStudio than rsthemes, but having these themes be fixed would be excellent. As far as I can tell, the font used and zoom level make no difference.
I 'fixed' the problem by searching for all instances of font-weight and commenting them out.
For example:
Next, a chunk.