aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/document.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src/document.rs')
-rw-r--r--helix-view/src/document.rs55
1 files changed, 46 insertions, 9 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 579c6725..4d3586f1 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -1238,24 +1238,61 @@ impl Document {
}
pub fn text_format(&self, mut viewport_width: u16, theme: Option<&Theme>) -> TextFormat {
- if let Some(max_line_len) = self
+ let config = self.config.load();
+ let text_width = self
.language_config()
- .and_then(|config| config.max_line_length)
- {
- viewport_width = viewport_width.min(max_line_len as u16)
+ .and_then(|config| config.text_width)
+ .unwrap_or(config.text_width);
+ let soft_wrap_at_text_width = self
+ .language_config()
+ .and_then(|config| {
+ config
+ .soft_wrap
+ .as_ref()
+ .and_then(|soft_wrap| soft_wrap.wrap_at_text_width)
+ })
+ .or(config.soft_wrap.wrap_at_text_width)
+ .unwrap_or(false);
+ if soft_wrap_at_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 config = self.config.load();
- let soft_wrap = &config.soft_wrap;
+ let editor_soft_wrap = &config.soft_wrap;
+ let language_soft_wrap = self
+ .language
+ .as_ref()
+ .and_then(|config| config.soft_wrap.as_ref());
+ let enable_soft_wrap = language_soft_wrap
+ .and_then(|soft_wrap| soft_wrap.enable)
+ .or(editor_soft_wrap.enable)
+ .unwrap_or(false);
+ let max_wrap = language_soft_wrap
+ .and_then(|soft_wrap| soft_wrap.max_wrap)
+ .or(config.soft_wrap.max_wrap)
+ .unwrap_or(20);
+ let max_indent_retain = language_soft_wrap
+ .and_then(|soft_wrap| soft_wrap.max_indent_retain)
+ .or(editor_soft_wrap.max_indent_retain)
+ .unwrap_or(40);
+ let wrap_indicator = language_soft_wrap
+ .and_then(|soft_wrap| soft_wrap.wrap_indicator.clone())
+ .or_else(|| config.soft_wrap.wrap_indicator.clone())
+ .unwrap_or_else(|| "↪ ".into());
let tab_width = self.tab_width() as u16;
TextFormat {
- soft_wrap: soft_wrap.enable && viewport_width > 10,
+ soft_wrap: enable_soft_wrap && viewport_width > 10,
tab_width,
- max_wrap: soft_wrap.max_wrap.min(viewport_width / 4),
- max_indent_retain: soft_wrap.max_indent_retain.min(viewport_width * 2 / 5),
+ max_wrap: max_wrap.min(viewport_width / 4),
+ max_indent_retain: max_indent_retain.min(viewport_width * 2 / 5),
// avoid spinning forever when the window manager
// sets the size to something tiny
viewport_width,
- wrap_indicator: soft_wrap.wrap_indicator.clone().into_boxed_str(),
+ wrap_indicator: wrap_indicator.into_boxed_str(),
wrap_indicator_highlight: theme
.and_then(|theme| theme.find_scope_index("ui.virtual.wrap"))
.map(Highlight),