aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/state.rs
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-core/src/state.rs
parent13d1ea542e142e130a29266ad1414991e4d2e1e0 (diff)
Simplify line ending calculation.
Diffstat (limited to 'helix-core/src/state.rs')
-rw-r--r--helix-core/src/state.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/helix-core/src/state.rs b/helix-core/src/state.rs
index 7cecba29..ffe88c3f 100644
--- a/helix-core/src/state.rs
+++ b/helix-core/src/state.rs
@@ -159,10 +159,9 @@ impl State {
(Direction::Forward, Granularity::Character) => {
// Clamp to line
let line = text.char_to_line(pos);
- let start = text.line_to_char(line);
- let len = text.line(line).len_chars();
- // convert to 0-indexed, subtract another 1 because len_chars() counts \n
- let end = start + len.saturating_sub(2);
+ // Line end is pos at the start of next line - 1
+ // subtract another 1 because the line ends with \n
+ let end = text.line_to_char(line + 1).saturating_sub(2);
std::cmp::min(nth_next_grapheme_boundary(&text.slice(..), pos, count), end)
}
(Direction::Forward, Granularity::Word) => {