gadenbuie / rsthemes

🔮 Full RStudio IDE and Syntax Themes
https://www.garrickadenbuie.com/project/rsthemes/
Other
593 stars 44 forks source link

Themes which use font-weight shift cursor position #80

Closed smingerson closed 2 years ago

smingerson commented 2 years ago

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:

  1. Set theme to a11y-dark. Other themes which use font-weighting may exhibit problems in different places.
  2. Create the following rmarkdown, or open another and examine a similar areas.
    
    ---
    title: "This bug makes me sad"
    output: 
    html_document
    ---
    # A heading 
    A heading
    Notice how the cursor is in slightly different positions relative to the "g" in heading when at the end of each line. 
    However, as headings get longer, the problem gets worst. So, if you can't tell the difference, make a longer heading

Next, a chunk.

# Notice it also happens with function calls. The more function calls on a line, the greater the discrepancy.
it(also(happens(with(fnction(calls())))))


RStudio information
RStudio 2021.09.1+372 "Ghost Orchid" Release (8b9ced188245155642d024aa3630363df611088a, 2021-11-08) for Windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36
gadenbuie commented 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: image

End of line: image

Function calls: image

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?

smingerson commented 2 years ago

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 image image image

gadenbuie commented 2 years ago

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)?

image

smingerson commented 2 years ago

I had it set to auto-detect. Unfortunately, behavior remains the same under all choices, which are the same as those listed for you.

Darxor commented 2 years ago

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.

gadenbuie commented 2 years ago

Thanks for the advice and thorough explanation @Darxor!

smingerson commented 2 years ago

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!