aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorJan Hrastnik2021-06-16 15:08:46 +0000
committerJan Hrastnik2021-06-16 15:08:46 +0000
commit9c419fe05cd51c96df29ac02e3dc5c73cae4ef97 (patch)
tree76ff55b9e16da5122787092c66ceb7613f39bc9b /helix-core/src
parent5eb69183926ab2f781aa08abf587ba338027854b (diff)
added more changes from pr review for line_ending_detection
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/lib.rs2
-rw-r--r--helix-core/src/line_ending.rs19
2 files changed, 6 insertions, 15 deletions
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<LineEnding> {
@@ -28,13 +26,9 @@ pub fn str_to_line_ending(g: &str) -> Option<LineEnding> {
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<LineEnding> {
ending
}
-pub fn default_line_ending() -> Option<LineEnding> {
- 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