diff options
author | Clément Delafargue | 2023-03-08 02:02:11 +0000 |
---|---|---|
committer | GitHub | 2023-03-08 02:02:11 +0000 |
commit | 8dd1ab48997fe774165b3aee5d366833c9660710 (patch) | |
tree | 3a60b99ae424514b3516301127623518de58fb16 /helix-core | |
parent | f4bdbe4674e6d023a63d2e64aec48c8c8598be67 (diff) |
Softwrapping improvements (#5893)
* 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 b247d526d69adf41434b6fd9c4983369c785aa22.
* 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>
Diffstat (limited to 'helix-core')
-rw-r--r-- | helix-core/src/syntax.rs | 30 | ||||
-rw-r--r-- | helix-core/src/wrap.rs | 4 |
2 files changed, 31 insertions, 3 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 1b6c1b1d..941e3ba7 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -82,7 +82,8 @@ pub struct LanguageConfiguration { pub shebangs: Vec<String>, // interpreter(s) associated with language pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml> pub comment_token: Option<String>, - pub max_line_length: Option<usize>, + pub text_width: Option<usize>, + pub soft_wrap: Option<SoftWrap>, #[serde(default, skip_serializing, deserialize_with = "deserialize_lsp_config")] pub config: Option<serde_json::Value>, @@ -546,6 +547,33 @@ impl LanguageConfiguration { .ok() } } +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default, rename_all = "kebab-case", deny_unknown_fields)] +pub struct SoftWrap { + /// Soft wrap lines that exceed viewport width. Default to off + pub enable: Option<bool>, + /// Maximum space left free at the end of the line. + /// This space is used to wrap text at word boundaries. If that is not possible within this limit + /// the word is simply split at the end of the line. + /// + /// This is automatically hard-limited to a quarter of the viewport to ensure correct display on small views. + /// + /// Default to 20 + pub max_wrap: Option<u16>, + /// Maximum number of indentation that can be carried over from the previous line when softwrapping. + /// If a line is indented further then this limit it is rendered at the start of the viewport instead. + /// + /// This is automatically hard-limited to a quarter of the viewport to ensure correct display on small views. + /// + /// Default to 40 + pub max_indent_retain: Option<u16>, + /// Indicator placed at the beginning of softwrapped lines + /// + /// Defaults to ↪ + pub wrap_indicator: Option<String>, + /// Softwrap at `text_width` instead of viewport width if it is shorter + pub wrap_at_text_width: Option<bool>, +} // Expose loader as Lazy<> global since it's always static? diff --git a/helix-core/src/wrap.rs b/helix-core/src/wrap.rs index eabc47d4..2ba8d173 100644 --- a/helix-core/src/wrap.rs +++ b/helix-core/src/wrap.rs @@ -2,6 +2,6 @@ use smartstring::{LazyCompact, SmartString}; /// Given a slice of text, return the text re-wrapped to fit it /// within the given width. -pub fn reflow_hard_wrap(text: &str, max_line_len: usize) -> SmartString<LazyCompact> { - textwrap::refill(text, max_line_len).into() +pub fn reflow_hard_wrap(text: &str, text_width: usize) -> SmartString<LazyCompact> { + textwrap::refill(text, text_width).into() } |