on master help sign in
fix: Indentation used different default on `hx` vs `hx new_file.txt`
commitc913bade0a3b0edaaf87e1a5e795edc951cead78 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 24 Oct 2021, 17:20 (5 years ago) parent4b4e972
1 file changed+8−8
helix-view/src/document.rs+8−8
helix-view/src/document.rs+8−8
@@ -23,6 +23,8 @@ use crate::{DocumentId, Theme, ViewId};
2323/// 8kB of buffer space for encoding and decoding `Rope`s.
2424const BUF_SIZE: usize = 8192;
2525
26+const DEFAULT_INDENT: IndentStyle = IndentStyle::Spaces(4);
27+
2628#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2729pub enum Mode {
2830 Normal,
@@ -325,7 +327,7 @@ impl Document {
325327 encoding,
326328 text,
327329 selections: HashMap::default(),
328− indent_style: IndentStyle::Spaces(4),
330+ indent_style: DEFAULT_INDENT,
329331 mode: Mode::Normal,
330332 restore_cursor: false,
331333 syntax: None,
@@ -495,17 +497,15 @@ impl Document {
495497 }
496498
497499 /// Detect the indentation used in the file, or otherwise defaults to the language indentation
498− /// configured in `languages.toml`, with a fallback back to 2 space indentation if it isn't
500+ /// configured in `languages.toml`, with a fallback to 4 space indentation if it isn't
499501 /// specified. Line ending is likewise auto-detected, and will fallback to the default OS
500502 /// line ending.
501503 pub fn detect_indent_and_line_ending(&mut self) {
502504 self.indent_style = auto_detect_indent_style(&self.text).unwrap_or_else(|| {
503− IndentStyle::from_str(
504− self.language
505− .as_ref()
506− .and_then(|config| config.indent.as_ref())
507− .map_or(" ", |config| config.unit.as_str()), // Fallback to 2 spaces.
508− )
505+ self.language
506+ .as_ref()
507+ .and_then(|config| config.indent.as_ref())
508+ .map_or(DEFAULT_INDENT, |config| IndentStyle::from_str(&config.unit))
509509 });
510510 self.line_ending = auto_detect_line_ending(&self.text).unwrap_or(DEFAULT_LINE_ENDING);
511511 }