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 minimum gutter line number spacing #18021

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

Conversation

galenelias
Copy link
Contributor

@galenelias galenelias commented Sep 18, 2024

I was inspecting how Zed did the layout in the editor, specifically for the gutter, and noticed that em_width * X is being used as the 'width of X consecutive characters'. Howevever, that math didn't work for me, because em_width doesn't account for the space between characters, so you can't just multiply it by a character count.

One place this is actually noticeable is in the logic for min_width_for_number_on_gutter, where we try to reserve 4 characters of line number space. However, once you actually hit 4 characters, the actual width is bigger, causing things to resize. This seems clearly counter to the intent of the code.

It seems the more correct logic is to use em_advance which accounts for the space between the characters. I am leaving the rest of the uses of em_width for generic padding. It is also possible that column_pixels() would be the more correct fix here, but it wasn't straightforward to use that due to it residing EditorElement source file.

On my MacBook this increases the width of the gutter by 6 pixels when there are <999 lines in the file, otherwise it's identical.

It might be worth doing some more general audit of some of the other uses of em_width as a concept. (e.g. git_blame_entries_width)

zed-gutter-resize.mov

Release Notes:

  • N/A

I was studying how Zed did the layout in the editor, specifically for
the gutter, and noticed that em_width * X is being used as the 'size of
X consecutive' characters. Howevever, that math didn't work for me,
because em_width doesn't account for the space between characters, so
you can't just multiply it by a character count.

One place this is actually noticeable is in the logic for
`min_width_for_number_on_gutter`, where we try to reserve 4 characters
of line number space.  However, once you actually hit 4 characters, the
actual size is bigger, causing things to resize.  This seems clearly
counter to the intent of the code.

It seems the more correct logic is to use `em_advance` which accounts
for the space between the characters.  I am leaving the rest of the uses
of `em_width` for generic padding. It is also possible that
`column_pixels()` would be the more correct fix here, but it wasn't
straightforward to use that due to it residing EditorElement source
file.

On my MacBook this increases the width of the gutter by 6 pixels when
there are <999 lines in the file, otherwise it's identical.

It might be worth doing some more general audit of some of the other
uses of em_width as a concept.  (e.g. `git_blame_entries_width`)
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant