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

editor: Adjust how gutter width is calculated to work with proportional fonts #24009

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TimmyMcPickles
Copy link

@TimmyMcPickles TimmyMcPickles commented Jan 31, 2025

Edited editor.rs line 14114, element.rs lines 6403, 6485, and 6491 from an 'm' to '0'

Closes #21860

This is my first real pull request, so please let me know how I can improve if you'd like

Release Notes:

  • Adjusted how the gutter width is calculated to work better with proportional fonts.

…lement.rs lines 6403, 6485, and 6491 from an 'm' to '0'
Copy link

cla-bot bot commented Jan 31, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @TimmyMcPickles on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@TimmyMcPickles
Copy link
Author

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 31, 2025
Copy link

cla-bot bot commented Jan 31, 2025

The cla-bot has been summoned, and re-checked this pull request!

@maxdeviant maxdeviant changed the title Working on issue #21860 Change width of em Jan 31, 2025
@@ -14111,7 +14111,7 @@ impl Editor {

let em_width = window
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're changing the measured glyph from an m to something else, it is no longer an "em width".

We should rename the surrounding bindings to be named something else. Maybe digit_width or numeral_width.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we change this for em_advance too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CSS they refer to this as a ch:

Represents the width or, more precisely, the advance measure of the glyph 0 (zero, the Unicode character U+0030) in the element's font. In cases where determining the measure of the 0 glyph is impossible or impractical, it must be assumed to be 0.5em wide by 1em tall.

https://developer.mozilla.org/en-US/docs/Web/CSS/length#ch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we change this for em_advance too?

Yes, we would.

Let's go with ch_width and ch_advance.

@@ -6482,13 +6482,13 @@ impl Element for EditorElement {
let line_height = style.text.line_height_in_pixels(window.rem_size());
let em_width = window
.text_system()
.typographic_bounds(font_id, font_size, 'm')
.typographic_bounds(font_id, font_size, '0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the em values here seems incorrect, because while it will impact the gutter dimensions, we also use the em width down below when computing the editor width and the wrap, which needs to stay in ems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to do this then I think we need to compute both an em and a ch and use the ch just for the gutter measurements and the em for everything else.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fairly new to rust. How would we calculate ch and em here?

@maxdeviant maxdeviant changed the title Change width of em editor: Adjust how gutter width is calculated to work with proportional fonts Jan 31, 2025
@maxdeviant maxdeviant self-assigned this Jan 31, 2025
@flvrone
Copy link
Contributor

flvrone commented Jan 31, 2025

Hey @maxdeviant, would you please consider checking my (local for now) PR instead?
flvrone#1

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.

Change how the width of the gutter is calculated considering propotional fonts.
4 participants