From 701eb0dd6800e75116f36e503787dd0f50df709e Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Sun, 20 Jun 2021 01:24:36 +0200 Subject: changed some hardcoded newlines, removed a else if in line_ending.rs --- helix-core/src/line_ending.rs | 5 ++--- helix-core/src/movement.rs | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'helix-core/src') diff --git a/helix-core/src/line_ending.rs b/helix-core/src/line_ending.rs index 2cc5b5d8..33f8d078 100644 --- a/helix-core/src/line_ending.rs +++ b/helix-core/src/line_ending.rs @@ -38,9 +38,8 @@ impl LineEnding { pub fn rope_slice_to_line_ending(g: &RopeSlice) -> Option { if let Some(text) = g.as_str() { str_to_line_ending(text) - } else if g == "\u{000D}\u{000A}" { - Some(LineEnding::Crlf) - } else { + } + else { // Not a line ending None } diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index 8b1e802f..cf7ea854 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, + pos_at_coords, Position, Range, RopeSlice, get_line_ending }; #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -38,7 +38,9 @@ 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(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)); nth_next_grapheme_boundary(slice, pos, count).min(end) } }; -- cgit v1.2.3-70-g09d2