diff --git a/book/src/configuration.md b/book/src/configuration.md index 1fcd5735a80a9..63d35c68ae1b1 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -317,12 +317,13 @@ Currently unused Options for soft wrapping lines that exceed the view width -| Key | Description | Default | -| --- | --- | --- | -| `enable` | Whether soft wrapping is enabled. | `false` | -| `max-wrap` | Maximum free space left at the end of the line. | `20` | -| `max-indent-retain` | Maximum indentation to carry over when soft wrapping a line. | `40` | -| `wrap-indicator` | Text inserted before soft wrapped lines, highlighted with `ui.virtual.wrap` | `↪ ` | +| Key | Description | Default | +| --- | --- | --- | +| `enable` | Whether soft wrapping is enabled. | `false` | +| `max-wrap` | Maximum free space left at the end of the line. | `20` | +| `max-indent-retain` | Maximum indentation to carry over when soft wrapping a line. | `40` | +| `wrap-indicator` | Text inserted before soft wrapped lines, highlighted with `ui.virtual.wrap` | `↪ ` | +| `wrap-at-text-width` | Soft wrap at `text-width` instead of using the full viewport size. | `true` | Example: diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 02cbac63d562f..034b704b11e4a 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1236,13 +1236,15 @@ impl Document { .language_config() .and_then(|config| config.text_width) .or_else(|| config.text_width); - if let Some(text_width) = text_width { - // We increase max_line_len by 1 because softwrap considers the newline character - // as part of the line length while the "typical" expectation is that this is not the case. - // In particular other commands like :reflow do not count the line terminator. - // This is technically inconsistent for the last line as that line never has a line terminator - // but having the last visual line exceed the width by 1 seems like a rare edge case. - viewport_width = viewport_width.min(text_width as u16 + 1) + if config.soft_wrap.wrap_at_text_width { + if let Some(text_width) = text_width { + // We increase max_line_len by 1 because softwrap considers the newline character + // as part of the line length while the "typical" expectation is that this is not the case. + // In particular other commands like :reflow do not count the line terminator. + // This is technically inconsistent for the last line as that line never has a line terminator + // but having the last visual line exceed the width by 1 seems like a rare edge case. + viewport_width = viewport_width.min(text_width as u16 + 1) + } } let soft_wrap = &config.soft_wrap; let tab_width = self.tab_width() as u16; diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index baf4dba0b989f..278755d977880 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -302,6 +302,8 @@ pub struct SoftWrap { /// /// Defaults to ↪ pub wrap_indicator: String, + /// Softwrap at `text_width` instead of viewport width if it is shorter + pub wrap_at_text_width: bool, } impl Default for SoftWrap { @@ -311,6 +313,7 @@ impl Default for SoftWrap { max_wrap: 20, max_indent_retain: 40, wrap_indicator: "↪ ".into(), + wrap_at_text_width: true, } } }