From 36f2b1f3b9c36ace65852d971f998a090cf9b5d5 Mon Sep 17 00:00:00 2001 From: Bernardo Date: Sat, 22 Dec 2018 12:59:48 +0100 Subject: iterate over `Step`s which are either, newlines or multibyte chars --- crates/ra_editor/src/line_index.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'crates/ra_editor/src/line_index.rs') diff --git a/crates/ra_editor/src/line_index.rs b/crates/ra_editor/src/line_index.rs index 7d9b8d79f..c29e2e49a 100644 --- a/crates/ra_editor/src/line_index.rs +++ b/crates/ra_editor/src/line_index.rs @@ -15,9 +15,9 @@ pub struct LineCol { } #[derive(Clone, Debug, Hash, PartialEq, Eq)] -struct Utf16Char { - start: TextUnit, - end: TextUnit, +pub(crate) struct Utf16Char { + pub(crate) start: TextUnit, + pub(crate) end: TextUnit, } impl Utf16Char { @@ -122,7 +122,13 @@ impl LineIndex { } pub(crate) fn newlines(&self) -> &[TextUnit] { - &self.newlines[1..] + &self.newlines[..] + } + + pub(crate) fn utf16_chars(&self, newline_idx: usize) -> Option<&[Utf16Char]> { + self.utf16_lines + .get(&(newline_idx as u32)) + .map(|x| x.as_slice()) } } -- cgit v1.2.3