From 9c419fe05cd51c96df29ac02e3dc5c73cae4ef97 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Wed, 16 Jun 2021 17:08:46 +0200 Subject: added more changes from pr review for line_ending_detection --- helix-core/src/lib.rs | 2 +- helix-core/src/line_ending.rs | 19 +++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) (limited to 'helix-core/src') diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs index bc25b1be..758e614e 100644 --- a/helix-core/src/lib.rs +++ b/helix-core/src/lib.rs @@ -110,5 +110,5 @@ pub use syntax::Syntax; pub use diagnostic::Diagnostic; pub use state::State; -pub use line_ending::{auto_detect_line_ending, default_line_ending, LineEnding}; +pub use line_ending::{auto_detect_line_ending, DEFAULT_LINE_ENDING, LineEnding}; pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction}; diff --git a/helix-core/src/line_ending.rs b/helix-core/src/line_ending.rs index 8e9b2ec0..809dffc0 100644 --- a/helix-core/src/line_ending.rs +++ b/helix-core/src/line_ending.rs @@ -1,16 +1,14 @@ use crate::{Rope, RopeGraphemes, RopeSlice}; /// Represents one of the valid Unicode line endings. +/// VT, FF and PS are excluded here, as we don't expect them to show up as a default line break #[derive(PartialEq, Copy, Clone, Debug)] pub enum LineEnding { Crlf, // CarriageReturn followed by LineFeed LF, // U+000A -- LineFeed - VT, // U+000B -- VerticalTab - FF, // U+000C -- FormFeed CR, // U+000D -- CarriageReturn Nel, // U+0085 -- NextLine LS, // U+2028 -- Line Separator - PS, // U+2029 -- ParagraphSeparator } pub fn rope_slice_to_line_ending(g: &RopeSlice) -> Option { @@ -28,13 +26,9 @@ pub fn str_to_line_ending(g: &str) -> Option { match g { "\u{000D}\u{000A}" => Some(LineEnding::Crlf), "\u{000A}" => Some(LineEnding::LF), - "\u{000B}" => Some(LineEnding::VT), - "\u{000C}" => Some(LineEnding::FF), "\u{000D}" => Some(LineEnding::CR), "\u{0085}" => Some(LineEnding::Nel), "\u{2028}" => Some(LineEnding::LS), - "\u{2029}" => Some(LineEnding::PS), - // Not a line ending _ => None, } @@ -65,10 +59,7 @@ pub fn auto_detect_line_ending(doc: &Rope) -> Option { ending } -pub fn default_line_ending() -> Option { - if cfg!(windows) { - Some(LineEnding::Crlf) - } else { - Some(LineEnding::LF) - } -} +#[cfg(target_os = "windows")] +pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Crlf; +#[cfg(not(target_os = "windows"))] +pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Lf; \ No newline at end of file -- cgit v1.2.3-70-g09d2