diff options
author | Nathan Vegdahl | 2021-07-22 18:17:03 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-22 18:17:03 +0000 |
commit | 5841954f58702ba2eabc17d96f0bf167cb13af24 (patch) | |
tree | f9fc4febfe658b36ee7a03790480d2bdd8722f56 /helix-core | |
parent | 673338bdb6064ff98e8822a251fd31664909610d (diff) |
Calculate the line that the range head is on correctly.
Diffstat (limited to 'helix-core')
-rw-r--r-- | helix-core/src/selection.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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] |