summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirawi2021-07-15 02:22:34 +0000
committerGitHub2021-07-15 02:22:34 +0000
commit0b1ed8656db35397122c1c2779e31bf86e38c430 (patch)
treebf6c088cd0828db13b744e0b524cc82c6fe9c3cf
parentd84b3a198a04c1c6931f07ab2fac5a3050bd7cff (diff)
Fix #442 (#446)
* fix #442 fix #442 fmt * create Rope from default line ending * Fix use of encoding in Document::open()
-rw-r--r--helix-view/src/document.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index a2bd1c41..8fdf7d98 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -456,14 +456,16 @@ impl Document {
theme: Option<&Theme>,
config_loader: Option<&syntax::Loader>,
) -> Result<Self, Error> {
- if !path.exists() {
- return Ok(Self::default());
- }
+ let (mut rope, encoding) = if path.exists() {
+ let mut file =
+ std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
+ from_reader(&mut file, encoding)?
+ } else {
+ let encoding = encoding.unwrap_or(encoding_rs::UTF_8);
+ (Rope::from(DEFAULT_LINE_ENDING.as_str()), encoding)
+ };
- let mut file = std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
- let (mut rope, encoding) = from_reader(&mut file, encoding)?;
let line_ending = with_line_ending(&mut rope);
-
let mut doc = Self::from(rope, Some(encoding));
// set the path and try detecting the language