aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
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
parent701eb0dd6800e75116f36e503787dd0f50df709e (diff)
added the line_end helper function
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/lib.rs2
-rw-r--r--helix-core/src/line_ending.rs6
-rw-r--r--helix-core/src/movement.rs6
3 files changed, 9 insertions, 5 deletions
diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs
index 9ac506a6..d99bb66d 100644
--- a/helix-core/src/lib.rs
+++ b/helix-core/src/lib.rs
@@ -114,6 +114,6 @@ pub use state::State;
pub use line_ending::{
auto_detect_line_ending, get_line_ending, rope_slice_to_line_ending, LineEnding,
- DEFAULT_LINE_ENDING,
+ DEFAULT_LINE_ENDING, line_end
};
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 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"))]
diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs
index cf7ea854..a3cd9b96 100644
--- a/helix-core/src/movement.rs
+++ b/helix-core/src/movement.rs
@@ -5,7 +5,7 @@ use ropey::iter::Chars;
use crate::{
coords_at_pos,
graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary},
- pos_at_coords, Position, Range, RopeSlice, get_line_ending
+ pos_at_coords, Position, Range, RopeSlice, get_line_ending, line_end
};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -38,9 +38,7 @@ pub fn move_horizontally(
}
Direction::Forward => {
// Line end is pos at the start of next line - 1
- let end = slice.line_to_char(line + 1).saturating_sub(get_line_ending(&slice.line(line))
- .map(|le| le.len_chars())
- .unwrap_or(0));
+ let end = line_end(&slice, line);
nth_next_grapheme_boundary(slice, pos, count).min(end)
}
};