-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Softwrapping improvements #5893
Conversation
Helix softwrap implementation always wraps lines so that the newline character doesn't get cut off so he line wraps one chars earlier then in other editors. This is necessary, because newline chars are always selecatble in helix and must never be hidden. However That means that `max_line_width` currently wraps one char earlier than expected. The typical definition of line width does not include the newline character and other helix commands like `:reflow` also don't count the newline character here. This commit makes softwrap use `max_line_width + 1` instead of `max_line_width` to correct the impedance missmatch.
looks like some checks are failing, something todo with xtask, that probably didn't exist yet when the original PR was made :D |
Alright, i've done the cleanup tasks. Next, i will make the global One thing to note is that once a global |
When it was only used for `:reflow` it made sense to have a default value set to `80`, but now that soft-wrapping uses this setting, keeping a default set to `80` would make soft-wrapping behave more aggressively.
Alright, i
I'm sure the wording of comments and documentation could be improved, don't hesitate to add suggestions |
e69ade3
to
0a8cdeb
Compare
0a8cdeb
to
7bff2a1
Compare
Softwrapping wraps by default to the viewport width or a configured `text-width` (whichever's smaller). In some cases we only want to set `text-width` to use for hard-wrapping and let longer lines flow if they have enough space. This setting allows that.
7bff2a1
to
ee5f48d
Compare
helix-term/src/commands/typed.rs
Outdated
.and_then(|config| config.max_line_length) | ||
}) | ||
.or_else(|| doc.language_config().and_then(|config| config.text_width)) | ||
.or(cfg_text_width) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it make more sense to no-op when no text_width value is set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be a pretty bad user experience since the default for the global text-width is None
so by default :reflow
would do nothing. Why are we defaulting to 79 instead of 80 here btw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
It was added in f9baced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the default to 80 here as we are breaking configs anyway. Seems like that was just missed in the original PR.
@archseer also braught that up in #2423 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking about more, i think it makes more sense to make text-width
always defined with a default value of 80 instead of having this hardcoded number, and maybe make softwrap ignore text-width
by default (i was quite surprised by the current behaviour, at first i thought it was a bug)
The issue is tagged |
A PR is usally tagged as In this case that would be #5893 (comment). Usually I don't lay out the entire solution and just give comments and let the authors figure out a good solution from there. But since you asked here is my idea how this should be addressed:
I would love to see this PR merge before the next release so if you are unsure how to proceed please just ask :) |
Yeah that's why I asked, i was not sure if #5893 (comment) was just a suggestion for further improvement or a blocking issue. Since this PR introduces a breaking change and it is added to the release milestone, i guess getting things right the first time is important. I'll give your idea a try and lay out pros/cons for other solutions so that we can move ahead. |
In general you can consider all my review comments intended as blocking issues unless during a review I explicitly say otherwise. I can see how that comment didn't sound as autharative and could be taken the wrong way if you didn't know that so it's good you asked to avoid misunderstandings :) yeah for a breaking changes to the config (especially one in a realease milestone) we want to make sure it's the right change to minimize the number of breaking changes. |
i'm not super comfortable with having the same option live in two different places in the editor-wide config and in language-specific config. The alternative is to be able to override the whole softwrap config in language settings, or maybe to add a Agreed on |
Yeah that might be better and more futurue proof as it allows overwriting all softwrap options per language 👍 That would require moving the |
another solution would be to define a dedicated
if there is something my haskell days have taught me, is to not be shy with creating new types instead of trying to co-opt existing ones, even when they seem close (there are tricks to have a single definition where fields can be optional or not depending on context, but that might not be idiomatic rust) |
I would prefer avoidng duplicating this struct. It's really just a convenience feature to use the I also would love if this PR could already add these additional config options in one go. It would be really great to have and something people have been asking for. Usually I am all for split things like these out to a across separate PR but adding support for all fields is really quite trivial and essentially just requires a line like I have shown above. |
the downside is that it puts default values at use site instead of having them in one place (it can be solved by constants, but it would make things a bit gnarly). Another possible issue i have noticed when working on To be clear: i think having the config type faithfully model optional config options would be a good thing in general, but in practice the codebase relies on the TOML serialization of this type being a fully defined values, with all possible values defined. Fixing this coupling would be a good thing, but maybe out of scope. |
This reverts commit b247d52.
a5eceaf
to
51d9f30
Compare
Don't worry neither There is only a single place that the |
alright, i have added support for per-language softwrap settings. I'm still not super satisfied with the default values moving away from the
|
e2ce415
to
0c5bbe8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor nits otherwise this looks great now :)
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM now, thanks for tackling that. I definitely wanted to see consistent configuration for softwrap before the next release.
I am not sure what to do about :get
. It already returns null
for other configuration like the whitespace.render
configuration options which also have a more complex fallback behavior. My opinion is that this is a problem with the :get
command as fixing this would preclude us from doing any kind of non-trivial fallback logic in the config.
My take would be to have a type faithfully representing config file contents: everything optional, no default values, and a type representing the actual (computed) configuration. With this setup, overrides and default values are set in a single place (when computing actual configuration from the config files). So defaults are all grouped, and all use sites read from the computed config, so there is no risk of forgetting about overrides when using config values. This approach would make If the goal is eventually to let |
The problem with this approach is that something like The right way to do this is probably by keeping the raw toml I think this can be to future work tough as it would require larger changes and is a more fundemental problem that doesn't need to be tackeled here. |
* use max_line_width + 1 during softwrap to account for newline char Helix softwrap implementation always wraps lines so that the newline character doesn't get cut off so he line wraps one chars earlier then in other editors. This is necessary, because newline chars are always selecatble in helix and must never be hidden. However That means that `max_line_width` currently wraps one char earlier than expected. The typical definition of line width does not include the newline character and other helix commands like `:reflow` also don't count the newline character here. This commit makes softwrap use `max_line_width + 1` instead of `max_line_width` to correct the impedance missmatch. * fix typos Co-authored-by: Jonathan Lebon <jonathan@jlebon.com> * Add text-width to config.toml * text-width: update setting documentation * rename leftover config item * remove leftover max-line-length occurrences * Make `text-width` optional in editor config When it was only used for `:reflow` it made sense to have a default value set to `80`, but now that soft-wrapping uses this setting, keeping a default set to `80` would make soft-wrapping behave more aggressively. * Allow softwrapping to ignore `text-width` Softwrapping wraps by default to the viewport width or a configured `text-width` (whichever's smaller). In some cases we only want to set `text-width` to use for hard-wrapping and let longer lines flow if they have enough space. This setting allows that. * Revert "Make `text-width` optional in editor config" This reverts commit b247d52. * soft-wrap: allow per-language overrides * Update book/src/configuration.md Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de> * Update book/src/languages.md Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de> * Update book/src/configuration.md Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de> --------- Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de> Co-authored-by: Jonathan Lebon <jonathan@jlebon.com> Co-authored-by: Alex Boehm <alexb@ozrunways.com> Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
* use max_line_width + 1 during softwrap to account for newline char Helix softwrap implementation always wraps lines so that the newline character doesn't get cut off so he line wraps one chars earlier then in other editors. This is necessary, because newline chars are always selecatble in helix and must never be hidden. However That means that `max_line_width` currently wraps one char earlier than expected. The typical definition of line width does not include the newline character and other helix commands like `:reflow` also don't count the newline character here. This commit makes softwrap use `max_line_width + 1` instead of `max_line_width` to correct the impedance missmatch. * fix typos Co-authored-by: Jonathan Lebon <jonathan@jlebon.com> * Add text-width to config.toml * text-width: update setting documentation * rename leftover config item * remove leftover max-line-length occurrences * Make `text-width` optional in editor config When it was only used for `:reflow` it made sense to have a default value set to `80`, but now that soft-wrapping uses this setting, keeping a default set to `80` would make soft-wrapping behave more aggressively. * Allow softwrapping to ignore `text-width` Softwrapping wraps by default to the viewport width or a configured `text-width` (whichever's smaller). In some cases we only want to set `text-width` to use for hard-wrapping and let longer lines flow if they have enough space. This setting allows that. * Revert "Make `text-width` optional in editor config" This reverts commit b247d52. * soft-wrap: allow per-language overrides * Update book/src/configuration.md Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de> * Update book/src/languages.md Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de> * Update book/src/configuration.md Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de> --------- Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de> Co-authored-by: Jonathan Lebon <jonathan@jlebon.com> Co-authored-by: Alex Boehm <alexb@ozrunways.com> Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
This is a continuation of #2423
make globaltext-length
optionaltext-width
when softwrappingtext-width
when softwrapping (per-language)