From 5841954f58702ba2eabc17d96f0bf167cb13af24 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 22 Jul 2021 11:17:03 -0700 Subject: Calculate the line that the range head is on correctly. --- helix-core/src/selection.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'helix-core') diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index 3d4ee768..6ca52ebf 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -73,6 +73,18 @@ impl Range { std::cmp::max(self.anchor, self.head) } + /// The line number that the head is on (using 1-width semantics). + #[inline] + #[must_use] + pub fn head_line(&self, text: RopeSlice) -> usize { + let head = if self.anchor < self.head { + prev_grapheme_boundary(text, self.head) + } else { + self.head + }; + text.char_to_line(head) + } + /// The (inclusive) range of lines that the range overlaps. #[inline] #[must_use] -- cgit v1.2.3-70-g09d2