From 1bb01d27aed8b046ff1cb41d4932c303d3b4ad0d Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Tue, 29 Sep 2020 17:49:19 +0900 Subject: Simplify line ending calculation. --- helix-core/src/state.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'helix-core') 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) => { -- cgit v1.2.3-70-g09d2