diff options
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/document.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 8875f70d..49d270e4 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -9,10 +9,12 @@ use std::str::FromStr; use std::sync::Arc; use helix_core::{ + auto_detect_line_ending, chars::{char_is_linebreak, char_is_whitespace}, history::History, syntax::{LanguageConfiguration, LOADER}, - ChangeSet, Diagnostic, Rope, Selection, State, Syntax, Transaction, + ChangeSet, Diagnostic, LineEnding, Rope, Selection, State, Syntax, Transaction, + DEFAULT_LINE_ENDING, }; use crate::{DocumentId, ViewId}; @@ -97,6 +99,7 @@ pub struct Document { diagnostics: Vec<Diagnostic>, language_server: Option<Arc<helix_lsp::Client>>, + line_ending: LineEnding, } use std::fmt; @@ -243,6 +246,7 @@ impl Document { history: Cell::new(History::default()), last_saved_revision: 0, language_server: None, + line_ending: DEFAULT_LINE_ENDING, } } @@ -262,10 +266,14 @@ impl Document { doc }; + // search for line endings + let line_ending = auto_detect_line_ending(&doc).unwrap_or(DEFAULT_LINE_ENDING); + let mut doc = Self::new(doc); // set the path and try detecting the language doc.set_path(&path)?; doc.detect_indent_style(); + doc.set_line_ending(line_ending); Ok(doc) } @@ -525,6 +533,10 @@ impl Document { self.selections.insert(view_id, selection); } + pub fn set_line_ending(&mut self, line_ending: LineEnding) { + self.line_ending = line_ending; + } + fn _apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool { let old_doc = self.text().clone(); @@ -795,6 +807,10 @@ impl Document { pub fn set_diagnostics(&mut self, diagnostics: Vec<Diagnostic>) { self.diagnostics = diagnostics; } + + pub fn line_ending(&self) -> LineEnding { + self.line_ending + } } #[cfg(test)] |