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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

.text_system()
.typographic_bounds(font_id, font_size, 'm')
.typographic_bounds(font_id, font_size, '0')
.unwrap()
.size
.width;
Expand Down
12 changes: 6 additions & 6 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ impl EditorElement {
let font_size = style.text.font_size.to_pixels(window.rem_size());
let em_width = window
.text_system()
.typographic_bounds(font_id, font_size, 'm')
.typographic_bounds(font_id, font_size, '0')
.unwrap()
.size
.width;
Expand Down Expand Up @@ -6400,7 +6400,7 @@ impl Element for EditorElement {
style.text.font_size.to_pixels(window.rem_size());
let em_width = window
.text_system()
.typographic_bounds(font_id, font_size, 'm')
.typographic_bounds(font_id, font_size, '0')
.unwrap()
.size
.width;
Expand Down Expand Up @@ -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?

.unwrap()
.size
.width;
let em_advance = window
.text_system()
.advance(font_id, font_size, 'm')
.advance(font_id, font_size, '0')
.unwrap()
.width;

Expand Down Expand Up @@ -8062,13 +8062,13 @@ fn compute_auto_height_layout(
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')
.unwrap()
.size
.width;
let em_advance = window
.text_system()
.advance(font_id, font_size, 'm')
.advance(font_id, font_size, '0')
.unwrap()
.width;

Expand Down
Loading