Skip to content

Commit

Permalink
Allow softwrapping to ignore text-width
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
divarvel committed Feb 10, 2023
1 parent b247d52 commit ee5f48d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
13 changes: 7 additions & 6 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
18 changes: 10 additions & 8 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,14 +1235,16 @@ impl Document {
let text_width = self
.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)
.or(config.text_width);
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;
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -311,6 +313,7 @@ impl Default for SoftWrap {
max_wrap: 20,
max_indent_retain: 40,
wrap_indicator: "↪ ".into(),
wrap_at_text_width: true,
}
}
}
Expand Down

0 comments on commit ee5f48d

Please sign in to comment.