on master help sign in
Fix #442 (#446)

* fix #442 fix #442 fmt * create Rope from default line ending * Fix use of encoding in Document::open()

commit0b1ed8656db35397122c1c2779e31bf86e38c430 authorKirawi <67773714+kirawi@users.noreply.github.com> dateWed 14 Jul 2021, 22:22 (5 years ago) parentd84b3a1
1 file changed+8−6
helix-view/src/document.rs+8−6
helix-view/src/document.rs+8−6
@@ -456,14 +456,16 @@ impl Document {
456456 theme: Option<&Theme>,
457457 config_loader: Option<&syntax::Loader>,
458458 ) -> Result<Self, Error> {
459− if !path.exists() {
460− return Ok(Self::default());
461− }
459+ let (mut rope, encoding) = if path.exists() {
460+ let mut file =
461+ std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
462+ from_reader(&mut file, encoding)?
463+ } else {
464+ let encoding = encoding.unwrap_or(encoding_rs::UTF_8);
465+ (Rope::from(DEFAULT_LINE_ENDING.as_str()), encoding)
466+ };
462467
463− let mut file = std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
464− let (mut rope, encoding) = from_reader(&mut file, encoding)?;
465468 let line_ending = with_line_ending(&mut rope);
466−
467469 let mut doc = Self::from(rope, Some(encoding));
468470
469471 // set the path and try detecting the language