zed icon indicating copy to clipboard operation
zed copied to clipboard

Make minimum width for line numbers in gutter configurable

Open maxmynter opened this issue 5 months ago • 4 comments

Closes #7334

Changes

This PR makes the minimum width allocated for line numbers in the side gutter configurable in units of character width via the "line_number_base_width" attribute in gutter settings. Set the previously hard coded value of 4 as default.

Together with other settings ("folds", "breakpoints",...) this gives the user control over the gutter width.

If the number of lines exceedes the base width, the number of digits in the largest line number is chosen instead. This is consistent with previous behaviour.

Screenshot for reference: Screenshot 2025-06-03 at 12 15 29

P.S.: This is my first time contributing to zed (yay!🎉). Let me know if i'm missing something.

Release Notes:

  • Make minimum line number width in gutter configurable

maxmynter avatar Jun 03 '25 10:06 maxmynter

We require contributors to sign our Contributor License Agreement, and we don't have @maxmynter 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'.

cla-bot[bot] avatar Jun 03 '25 10:06 cla-bot[bot]

@cla-bot check

maxmynter avatar Jun 03 '25 10:06 maxmynter

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

cla-bot[bot] avatar Jun 03 '25 10:06 cla-bot[bot]

Punctuation of comments adressed in 8f6403c

maxmynter avatar Jun 03 '25 12:06 maxmynter

There was a CI failure because of formatting but a merge conflict after cargo fmt so i rebased this change onto the current tip of main -- that's why the force pushing.

Give me a couple minutes. I'll change the comment and rerequest if tests pass for merging.

maxmynter avatar Jun 11 '25 09:06 maxmynter

Which character is used to measure the width? The last time I checked, it was ‘m’, and it didn't seem to have changed when I looked at these commits. In many fonts, ‘m’ is too wide to estimate widths of numbers. I think that ‘0’ would be much better for that.

matj1 avatar Jun 11 '25 10:06 matj1

Great thought, but why post in a closed PR that does something slightly different, mainly fiddles with configs?

Either way, the PR with two pictures will show things better than any words.

SomeoneToIgnore avatar Jun 11 '25 10:06 SomeoneToIgnore

Because this PR solves #7334, and I hoped that solving that would let me make the gutter not too wide with proportional fonts. If I understand it correctly, the gutter is at least x em wide when the largest line number is x-digit. That causes that the discrepancy of widths between ‘m’ and a digit accumulates with every digit of the longest line number, so it still makes the gutter unnecessarily wide.

Edit: This makes the width of the gutter configurable (the point of #7334), but only with small line numbers. With sufficiently large line numbers, the width ceases to be configurable.

matj1 avatar Jun 11 '25 10:06 matj1

This PR made the minimum width configurable. If you have long files, the gutter will (in the current implementation) always be wide enough to accomodate the largest line number which I think is sensible because the alternatives I can think of -- x scrollable gutter obscured line numbers, dynamic gutter width -- are janky.

There is a separate issue (#21860) that suggests using the width of 0 instead of m for the digit. That is a different discussion, though.

What is your desired behaviour for the gutter width of long files?

Edit: I added a PR for the use of ch-width (0) instead of em-width (m) here #32548 to address the proportional font issue.

maxmynter avatar Jun 11 '25 13:06 maxmynter

I think that my desired behavior is what is done in #32548, for which I thank you.

There are rare cases where this solution would not work, but even I consider these cases too rare for how much work solving them requires. Most proportional fonts have all digits of the same width, although ‘1’ may be narrower, which is usually negligible. The rare cases are when digits have wildly different widths, or when there are ligatures changing widths of certain sequences of digits; a solution to these would be to measure every used line number and choose the widest one, which is computationally complex.

matj1 avatar Jun 11 '25 14:06 matj1