From a9a718c3cad3af7b9fa38cd1aaa6ceb6c7126130 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Sun, 13 Jun 2021 21:38:31 +0200 Subject: added some tests and a line_ending helper function in document.rs --- helix-view/src/document.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'helix-view/src') diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 704094a6..bd5f8012 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -6,9 +6,9 @@ use std::sync::Arc; use helix_core::{ chars::{char_is_linebreak, char_is_whitespace}, - auto_detect_line_ending, DEFAULT_LINE_ENDING, history::History, syntax::{LanguageConfiguration, LOADER}, ChangeSet, Diagnostic, LineEnding, Rope, Selection, State, Syntax, Transaction, + DEFAULT_LINE_ENDING, }; use crate::{DocumentId, ViewId}; @@ -740,6 +740,20 @@ impl Document { pub fn set_diagnostics(&mut self, diagnostics: Vec) { self.diagnostics = diagnostics; } + + pub fn line_ending(&self) -> &str { + match self.line_ending { + LineEnding::Crlf => "\u{000D}\u{000A}", + LineEnding::LF => "\u{000A}", + LineEnding::Nel => "\u{0085}", + LineEnding::LS => "\u{2028}", + LineEnding::CR => "\u{000D}", + _ => panic!( + "Unexpected line ending: {:?}, expected Crlf, LF, CR, Nel, or LS.", + self.line_ending + ), + } + } } #[cfg(test)] -- cgit v1.2.3-70-g09d2