diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 7fbd7894f..df0407412 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1739,20 +1739,24 @@ fn reflow( return Ok(()); } + const DEFAULT_MAX_LEN: usize = 79; + let scrolloff = cx.editor.config().scrolloff; - let cfg_text_width: usize = cx.editor.config().text_width; + let cfg_text_width = cx.editor.config().text_width; let (view, doc) = current!(cx.editor); // Find the text_width by checking the following sources in order: // - The passed argument in `args` // - The configured text-width for this language in languages.toml - // - The configured text-width in the config.toml + // - The configured text-width in config.toml + // - The const default we set above let text_width: usize = args .get(0) .map(|num| num.parse::()) .transpose()? .or_else(|| doc.language_config().and_then(|config| config.text_width)) - .unwrap_or(cfg_text_width); + .or(cfg_text_width) + .unwrap_or(DEFAULT_MAX_LEN); let rope = doc.text(); diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index e066ea4a2..02cbac63d 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1231,7 +1231,12 @@ impl Document { } pub fn text_format(&self, mut viewport_width: u16, theme: Option<&Theme>) -> TextFormat { - if let Some(text_width) = self.language_config().and_then(|config| config.text_width) { + let config = self.config.load(); + 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. @@ -1239,7 +1244,6 @@ impl Document { // 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 tab_width = self.tab_width() as u16; TextFormat { diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 6683da2a5..baf4dba0b 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -242,7 +242,7 @@ pub struct Config { /// Automatic save on focus lost. Defaults to false. pub auto_save: bool, /// Set a global text_width - pub text_width: usize, + pub text_width: Option, /// Time in milliseconds since last keypress before idle timers trigger. /// Used for autocompletion, set to 0 for instant. Defaults to 400ms. #[serde( @@ -766,7 +766,7 @@ impl Default for Config { indent_guides: IndentGuidesConfig::default(), color_modes: false, soft_wrap: SoftWrap::default(), - text_width: 80, + text_width: None, } } }