summaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-09-29 08:49:19 +0000
committerBlaž Hrastnik2020-09-29 08:49:19 +0000
commit1bb01d27aed8b046ff1cb41d4932c303d3b4ad0d (patch)
tree545d4e05cbbd23119031027ec90a7317751413b8 /helix-view/src
parent13d1ea542e142e130a29266ad1414991e4d2e1e0 (diff)
Simplify line ending calculation.
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/commands.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs
index fc18e3a7..d611e4f6 100644
--- a/helix-view/src/commands.rs
+++ b/helix-view/src/commands.rs
@@ -50,9 +50,10 @@ pub fn move_line_end(view: &mut View, count: usize) {
.into_iter()
.map(|index| {
// adjust all positions to the end of the line.
- let line = view.state.doc.line(index);
- let line_start = view.state.doc.line_to_char(index);
- line_start + line.len_chars() - 1
+
+ // Line end is pos at the start of next line - 1
+ // subtract another 1 because the line ends with \n
+ view.state.doc.line_to_char(index + 1).saturating_sub(2)
})
.map(|pos| Range::new(pos, pos));
@@ -236,10 +237,8 @@ pub fn open_below(view: &mut View, _count: usize) {
let positions: Vec<_> = lines
.into_iter()
.map(|index| {
- // adjust all positions to the end of the line.
- let line = view.state.doc.line(index);
- let line_start = view.state.doc.line_to_char(index);
- line_start + line.len_chars()
+ // adjust all positions to the end of the line/start of the next one.
+ view.state.doc.line_to_char(index + 1)
})
.collect();