aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/line_ending.rs
diff options
context:
space:
mode:
authorJan Hrastnik2021-06-20 00:22:10 +0000
committerJan Hrastnik2021-06-20 00:22:10 +0000
commit8634e04a31f8f761b3d0505528295d31d63c7918 (patch)
tree07bf80760d41f2f13c125bc38e15b0dd389d64f1 /helix-core/src/line_ending.rs
parent701eb0dd6800e75116f36e503787dd0f50df709e (diff)
added the line_end helper function
Diffstat (limited to 'helix-core/src/line_ending.rs')
-rw-r--r--helix-core/src/line_ending.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/helix-core/src/line_ending.rs b/helix-core/src/line_ending.rs
index 33f8d078..f6118493 100644
--- a/helix-core/src/line_ending.rs
+++ b/helix-core/src/line_ending.rs
@@ -111,6 +111,12 @@ pub fn get_line_ending(line: &RopeSlice) -> Option<LineEnding> {
str_to_line_ending(g2).or_else(|| str_to_line_ending(g1))
}
+pub fn line_end(slice: &RopeSlice, line: usize) -> usize {
+ slice.line_to_char(line + 1).saturating_sub(get_line_ending(&slice.line(line))
+ .map(|le| le.len_chars())
+ .unwrap_or(0))
+}
+
#[cfg(target_os = "windows")]
pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Crlf;
#[cfg(not(target_os = "windows"))]