editor: Push em width calculations down into EditorSnapshot::gutter_dimensions (#24062)

This PR removes the `em_width` and `em_advance` parameters to
`EditorSnapshot::gutter_dimensions` in favor of computing the values
inside of it.

In practice all of the callers were passing in the same values, and
there isn't a circumstance where we would want to pass in different
values.

`gutter_dimensions` has also been modified to return
`Option<GutterDimensions>` instead of `GutterDimensions` so that we can
remove some `.unwrap`s when interacting with the text system.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2025-02-01 00:10:42 +00:00
committed by GitHub
parent 17872260e6
commit 52a3013d73
3 changed files with 30 additions and 29 deletions
+11 -17
View File
@@ -6476,14 +6476,14 @@ impl Element for EditorElement {
let letter_size = size(em_width, line_height);
let gutter_dimensions = snapshot.gutter_dimensions(
font_id,
font_size,
em_width,
em_advance,
self.max_line_number_width(&snapshot, window, cx),
cx,
);
let gutter_dimensions = snapshot
.gutter_dimensions(
font_id,
font_size,
self.max_line_number_width(&snapshot, window, cx),
cx,
)
.unwrap_or_default();
let text_width = bounds.size.width - gutter_dimensions.width;
let editor_width = text_width - gutter_dimensions.margin - em_width;
@@ -8043,17 +8043,11 @@ fn compute_auto_height_layout(
let font_size = style.text.font_size.to_pixels(window.rem_size());
let line_height = style.text.line_height_in_pixels(window.rem_size());
let em_width = window.text_system().em_width(font_id, font_size).unwrap();
let em_advance = window.text_system().em_advance(font_id, font_size).unwrap();
let mut snapshot = editor.snapshot(window, cx);
let gutter_dimensions = snapshot.gutter_dimensions(
font_id,
font_size,
em_width,
em_advance,
max_line_number_width,
cx,
);
let gutter_dimensions = snapshot
.gutter_dimensions(font_id, font_size, max_line_number_width, cx)
.unwrap_or_default();
editor.gutter_dimensions = gutter_dimensions;
let text_width = width - gutter_dimensions.width;