on master help sign in
Use default line ending in open command (#7357)
d5af603Alex
helix-view/src/document.rs+5−4
@@ -31,7 +31,6 @@ use helix_core::{
31 line_ending::auto_detect_line_ending,
31 line_ending::auto_detect_line_ending,
32 syntax::{self, LanguageConfiguration},
32 syntax::{self, LanguageConfiguration},
33 ChangeSet, Diagnostic, LineEnding, Range, Rope, RopeBuilder, Selection, Syntax, Transaction,
33 ChangeSet, Diagnostic, LineEnding, Range, Rope, RopeBuilder, Selection, Syntax, Transaction,
34− NATIVE_LINE_ENDING,
35};
34};
36
35
37use crate::editor::{Config, RedrawHandle};
36use crate::editor::{Config, RedrawHandle};
@@ -625,7 +624,8 @@ impl Document {
625 }
624 }
626
625
627 pub fn default(config: Arc<dyn DynAccess<Config>>) -> Self {
626 pub fn default(config: Arc<dyn DynAccess<Config>>) -> Self {
627+ let line_ending: LineEnding = config.load().default_line_ending.into();
628− let text = Rope::from(NATIVE_LINE_ENDING.as_str());
628+ let text = Rope::from(line_ending.as_str());
629 Self::from(text, None, config)
629 Self::from(text, None, config)
630 }
630 }
631
631
@@ -644,8 +644,9 @@ impl Document {
644 std::fs::File::open(path).context(format!("unable to open {:?}", path))?;
644 std::fs::File::open(path).context(format!("unable to open {:?}", path))?;
645 from_reader(&mut file, encoding)?
645 from_reader(&mut file, encoding)?
646 } else {
646 } else {
647+ let line_ending: LineEnding = config.load().default_line_ending.into();
647 let encoding = encoding.unwrap_or(encoding::UTF_8);
648 let encoding = encoding.unwrap_or(encoding::UTF_8);
648− (Rope::from(NATIVE_LINE_ENDING.as_str()), encoding, false)
649+ (Rope::from(line_ending.as_str()), encoding, false)
649 };
650 };
650
651
651 let mut doc = Self::from(rope, Some((encoding, has_bom)), config);
652 let mut doc = Self::from(rope, Some((encoding, has_bom)), config);
@@ -1925,7 +1926,7 @@ mod test {
1925 Document::default(Arc::new(ArcSwap::new(Arc::new(Config::default()))))
1926 Document::default(Arc::new(ArcSwap::new(Arc::new(Config::default()))))
1926 .text()
1927 .text()
1927 .to_string(),
1928 .to_string(),
1928− NATIVE_LINE_ENDING.as_str()
1929+ helix_core::NATIVE_LINE_ENDING.as_str()
1929 );
1930 );
1930 }
1931 }
1931
1932