@@ -8,7 +8,6 @@ use helix_core::doc_formatter::TextFormat;
88use helix_core::encoding::Encoding;
99use helix_core::syntax::{Highlight, LanguageServerFeature};
1010use helix_core::text_annotations::{InlineAnnotation, TextAnnotations};
11−use helix_core::Range;
1211use helix_vcs::{DiffHandle, DiffProviderRegistry};
1312
1413use ::parking_lot::Mutex;
@@ -31,8 +30,8 @@ use helix_core::{
3130 indent::{auto_detect_indent_style, IndentStyle},
3231 line_ending::auto_detect_line_ending,
3332 syntax::{self, LanguageConfiguration},
34− ChangeSet, Diagnostic, LineEnding, Rope, RopeBuilder, Selection, Syntax, Transaction,
35− DEFAULT_LINE_ENDING,
33+ ChangeSet, Diagnostic, LineEnding, Range, Rope, RopeBuilder, Selection, Syntax, Transaction,
34+ NATIVE_LINE_ENDING,
3635};
3736
3837use crate::editor::{Config, RedrawHandle};
@@ -590,6 +589,7 @@ impl Document {
590589 config: Arc<dyn DynAccess<Config>>,
591590 ) -> Self {
592591 let (encoding, has_bom) = encoding_with_bom_info.unwrap_or((encoding::UTF_8, false));
592+ let line_ending = config.load().default_line_ending.into();
593593 let changes = ChangeSet::new(&text);
594594 let old_state = None;
595595
@@ -603,7 +603,7 @@ impl Document {
603603 inlay_hints: HashMap::default(),
604604 inlay_hints_oudated: false,
605605 indent_style: DEFAULT_INDENT,
606− line_ending: DEFAULT_LINE_ENDING,
606+ line_ending,
607607 restore_cursor: false,
608608 syntax: None,
609609 language: None,
@@ -623,10 +623,12 @@ impl Document {
623623 focused_at: std::time::Instant::now(),
624624 }
625625 }
626+
626627 pub fn default(config: Arc<dyn DynAccess<Config>>) -> Self {
627− let text = Rope::from(DEFAULT_LINE_ENDING.as_str());
628+ let text = Rope::from(NATIVE_LINE_ENDING.as_str());
628629 Self::from(text, None, config)
629630 }
631+
630632 // TODO: async fn?
631633 /// Create a new document from `path`. Encoding is auto-detected, but it can be manually
632634 /// overwritten with the `encoding` parameter.
@@ -643,7 +645,7 @@ impl Document {
643645 from_reader(&mut file, encoding)?
644646 } else {
645647 let encoding = encoding.unwrap_or(encoding::UTF_8);
646− (Rope::from(DEFAULT_LINE_ENDING.as_str()), encoding, false)
648+ (Rope::from(NATIVE_LINE_ENDING.as_str()), encoding, false)
647649 };
648650
649651 let mut doc = Self::from(rope, Some((encoding, has_bom)), config);
@@ -887,14 +889,16 @@ impl Document {
887889
888890 /// Detect the indentation used in the file, or otherwise defaults to the language indentation
889891 /// configured in `languages.toml`, with a fallback to tabs if it isn't specified. Line ending
890− /// is likewise auto-detected, and will fallback to the default OS line ending.
892+ /// is likewise auto-detected, and will remain unchanged if no line endings were detected.
891893 pub fn detect_indent_and_line_ending(&mut self) {
892894 self.indent_style = auto_detect_indent_style(&self.text).unwrap_or_else(|| {
893895 self.language_config()
894896 .and_then(|config| config.indent.as_ref())
895897 .map_or(DEFAULT_INDENT, |config| IndentStyle::from_str(&config.unit))
896898 });
897− self.line_ending = auto_detect_line_ending(&self.text).unwrap_or(DEFAULT_LINE_ENDING);
899+ if let Some(line_ending) = auto_detect_line_ending(&self.text) {
900+ self.line_ending = line_ending;
901+ }
898902 }
899903
900904 /// Reload the document from its path.
@@ -1921,7 +1925,7 @@ mod test {
19211925 Document::default(Arc::new(ArcSwap::new(Arc::new(Config::default()))))
19221926 .text()
19231927 .to_string(),
1924− DEFAULT_LINE_ENDING.as_str()
1928+ NATIVE_LINE_ENDING.as_str()
19251929 );
19261930 }
19271931