editor: Do not offset text in single line editors by default (#30599)

Follow-up to #30138

In the linked PR, I enabled the content offset for all editors by
default. However, this introduced a small regression: There are some
editors where we do not want the text to be offset, most notably the
rename and the filename editor.

This PR adds a method to disable the content offset for specific
editors. I specifically decided on an opt-out approach, since I think
that having the small offset for most editors is actually a benefit
instead of a disadvantage. However, open to change that or to disable
the offset for all editors but full mode editors by default if that
should be preferred.

| `main` | This PR |
| --- | --- |
|
![main](https://github.com/user-attachments/assets/a7e9249e-ac5c-422f-9f30-021ebf21850b)
|
![pr](https://github.com/user-attachments/assets/c5eef4e6-fad8-46ab-9f2d-d0ebdca01e2c)
|


Release Notes:

- N/A
This commit is contained in:
Finn Evers 2025-05-26 13:47:10 +02:00 committed by GitHub
parent e6f51966a1
commit 6363fdab88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 4 deletions

View file

@ -7343,9 +7343,12 @@ impl Element for EditorElement {
self.max_line_number_width(&snapshot, window, cx),
cx,
)
.unwrap_or_else(|| {
GutterDimensions::default_with_margin(font_id, font_size, cx)
});
.or_else(|| {
self.editor.read(cx).offset_content.then(|| {
GutterDimensions::default_with_margin(font_id, font_size, cx)
})
})
.unwrap_or_default();
let text_width = bounds.size.width - gutter_dimensions.width;
let settings = EditorSettings::get_global(cx);
@ -9391,7 +9394,12 @@ fn compute_auto_height_layout(
let mut snapshot = editor.snapshot(window, cx);
let gutter_dimensions = snapshot
.gutter_dimensions(font_id, font_size, max_line_number_width, cx)
.unwrap_or_else(|| GutterDimensions::default_with_margin(font_id, font_size, cx));
.or_else(|| {
editor
.offset_content
.then(|| GutterDimensions::default_with_margin(font_id, font_size, cx))
})
.unwrap_or_default();
editor.gutter_dimensions = gutter_dimensions;
let text_width = width - gutter_dimensions.width;