summaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-22 18:17:03 +0000
committerNathan Vegdahl2021-07-22 18:17:03 +0000
commit5841954f58702ba2eabc17d96f0bf167cb13af24 (patch)
treef9fc4febfe658b36ee7a03790480d2bdd8722f56 /helix-core/src
parent673338bdb6064ff98e8822a251fd31664909610d (diff)
Calculate the line that the range head is on correctly.
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/selection.rs12
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]