Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Use same amount of left pad as .cm-line #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mattmundell
Copy link
Contributor

@mattmundell mattmundell commented Dec 13, 2024

Why

The indent markers are drawn using backgrounds on a ::before element that is placed on CodeMirror lines (.cm-line). The left offsets of the indent markers should match the left pad of the .cm-line, however there is an error in the calculation.

The left offset of the indent marker is made up of:

  • 0.5ch that is added to the left offset of the background in createGradient
  • plus 2px that is set as the left value of the ::before element.

The 2px was added in #26 by @bradymadden97 to try fix the alignment but if you look closely at theme.tx#L85 the .cm-line left pad is 6px instead of 2px.

The offset of 0.5ch plus 2px is coming close, but see for example how the line under the 6 is shifting as I increase the font size:
before0
before1
before3

(Maybe zoom the first image yourself to see how far left it should be.)

This is because the size of 0.5ch depends on the font size, whereas the CodeMirror .cm-line offset is always fixed at 6 pixels.

What changed

Remove the extra 0.5ch offset from the background and change the ::before left from 2px to 6px.

Test plan

I tested using an app that uses CodeMirror. I enabled the indentation markers and then gradually increased the font size to confirm the drift.

After the PR the line stays in place when I increase the font size:
after0
after1
after3

@mattmundell
Copy link
Contributor Author

Note that the same happens in the Replit UI. It's easiest to see when choosing a Font Size of Huge in User Settings:

rep0

The red box is the cursor. It's an outline because the view does not have the focus. The grey line should align with the left of the cursor.

Maybe clearer when I modify --indent-marker-bg-color in devtools:

rep1

Compare with a Font Size of Small:

rep2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant