@@ -5,11 +5,14 @@ use std::path::{Component, Path, PathBuf};
55use std::sync::Arc;
66
77use helix_core::{
8+<<<<<<< HEAD
89 chars::{char_is_linebreak, char_is_whitespace},
910 history::History,
11+=======
12+ auto_detect_line_ending, default_line_ending,
13+>>>>>>> 491a8b3 (resolved conflict in rebase)
1014 syntax::{LanguageConfiguration, LOADER},
11− ChangeSet, Diagnostic, History, Rope, RopeGraphemes, RopeSlice, Selection, State, Syntax,
12− Transaction,
15+ ChangeSet, Diagnostic, History, LineEnding, Rope, Selection, State, Syntax, Transaction,
1316};
1417
1518use crate::{DocumentId, ViewId};
@@ -23,6 +26,7 @@ pub enum Mode {
2326 Insert,
2427}
2528
29+<<<<<<< HEAD
2630
2731#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2832pub enum IndentStyle {
@@ -45,6 +49,8 @@ pub enum LineEnding {
4549 PS = 8, // U+2029 -- ParagraphSeparator
4650}
4751
52+=======
53+>>>>>>> 491a8b3 (resolved conflict in rebase)
4854pub struct Document {
4955 // rope + selection
5056 pub(crate) id: DocumentId,
@@ -78,7 +84,7 @@ pub struct Document {
7884
7985 diagnostics: Vec<Diagnostic>,
8086 language_server: Option<Arc<helix_lsp::Client>>,
81− _line_ending: LineEnding,
87+ line_ending: Option<LineEnding>,
8288}
8389
8490use std::fmt;
@@ -164,61 +170,14 @@ pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> {
164170 std::env::current_dir().map(|current_dir| normalize_path(¤t_dir.join(path)))
165171}
166172
167−pub fn auto_detect_line_ending(doc: &Rope) -> LineEnding {
168− // based on https://github.com/cessen/led/blob/27572c8838a1c664ee378a19358604063881cc1d/src/editor/mod.rs#L88-L162
169−
170− let mut ending = LineEnding::None;
171− for line in doc.lines().take(1) { // check first line only - unsure how sound this is
172− ending = match line.len_chars() {
173− 1 => { let g = RopeGraphemes::new(line.slice((line.len_chars() - 1)..))
174− .last()
175− .unwrap();
176− rope_slice_to_line_ending(&g)}
177− n if n > 1 => { let g = RopeGraphemes::new(line.slice((line.len_chars() - 2)..))
178− .last()
179− .unwrap();
180− rope_slice_to_line_ending(&g) }
181− _ => LineEnding::None
182−
183− }
184− }
185− ending
186−}
187−
188−pub fn rope_slice_to_line_ending(g: &RopeSlice) -> LineEnding {
189− if let Some(text) = g.as_str() {
190− str_to_line_ending(text)
191− } else if g == "\u{000D}\u{000A}" {
192− LineEnding::Crlf
193− } else {
194− // Not a line ending
195− LineEnding::None
196− }
197−}
198−
199−pub fn str_to_line_ending(g: &str) -> LineEnding {
200− match g {
201− "\u{000D}\u{000A}" => LineEnding::Crlf,
202− "\u{000A}" => LineEnding::LF,
203− "\u{000B}" => LineEnding::VT,
204− "\u{000C}" => LineEnding::FF,
205− "\u{000D}" => LineEnding::CR,
206− "\u{0085}" => LineEnding::Nel,
207− "\u{2028}" => LineEnding::LS,
208− "\u{2029}" => LineEnding::PS,
209−
210− // Not a line ending
211− _ => LineEnding::None,
212− }
213−}
214−
215173use helix_lsp::lsp;
216174use url::Url;
217175
218176impl Document {
219− pub fn new(text: Rope, _line_ending: LineEnding) -> Self {
177+ pub fn new(text: Rope) -> Self {
220178 let changes = ChangeSet::new(&text);
221179 let old_state = None;
180+ let line_ending = default_line_ending();
222181
223182 Self {
224183 id: DocumentId::default(),
@@ -237,7 +196,7 @@ impl Document {
237196 history: Cell::new(History::default()),
238197 last_saved_revision: 0,
239198 language_server: None,
240− _line_ending
199+ line_ending,
241200 }
242201 }
243202
@@ -260,10 +219,14 @@ impl Document {
260219 // search for line endings
261220 let line_ending = auto_detect_line_ending(&doc);
262221
263− let mut doc = Self::new(doc, line_ending);
222+ let mut doc = Self::new(doc);
264223 // set the path and try detecting the language
265224 doc.set_path(&path)?;
225+<<<<<<< HEAD
266226 doc.detect_indent_style();
227+=======
228+ doc.set_line_ending(line_ending);
229+>>>>>>> 491a8b3 (resolved conflict in rebase)
267230
268231 Ok(doc)
269232 }
@@ -522,6 +485,10 @@ impl Document {
522485 self.selections.insert(view_id, selection);
523486 }
524487
488+ pub fn set_line_ending(&mut self, line_ending: Option<LineEnding>) {
489+ self.line_ending = line_ending;
490+ }
491+
525492 fn _apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
526493 let old_doc = self.text().clone();
527494