From dcfa4a63c6682bdc125b6f99c90166e1799c8ab0 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Fri, 3 Feb 2023 22:27:51 +0100 Subject: [PATCH 1/2] 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. --- helix-view/src/document.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 798b54006..ebc654af6 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1212,7 +1212,12 @@ impl Document { .language_config() .and_then(|config| config.max_line_length) { - viewport_width = viewport_width.min(max_line_len as u16) + // we increase max_line_len by 1 because softwrap considers the newline characterr + // as part of the line length while the "typical" expectiation 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 edgecase + viewport_width = viewport_width.min(max_line_len as u16 + 1) } let config = self.config.load(); let soft_wrap = &config.soft_wrap; From d370598fe52ab06e36f4851d22994351133cd0e8 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Fri, 3 Feb 2023 22:46:15 +0100 Subject: [PATCH 2/2] fix typos Co-authored-by: Jonathan Lebon --- helix-view/src/document.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index ebc654af6..1eced6052 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1212,11 +1212,11 @@ impl Document { .language_config() .and_then(|config| config.max_line_length) { - // we increase max_line_len by 1 because softwrap considers the newline characterr - // as part of the line length while the "typical" expectiation 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 edgecase + // 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(max_line_len as u16 + 1) } let config = self.config.load();