aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/selection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src/selection.rs')
-rw-r--r--helix-core/src/selection.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index c08f504d..074b6199 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -73,6 +73,20 @@ impl Range {
std::cmp::max(self.anchor, self.head)
}
+ /// The (inclusive) range of lines that the range overlaps.
+ #[inline]
+ #[must_use]
+ pub fn line_range(&self, text: RopeSlice) -> (usize, usize) {
+ let from = self.from();
+ let to = if self.is_empty() {
+ self.to()
+ } else {
+ prev_grapheme_boundary(text, self.to()).max(from)
+ };
+
+ (text.char_to_line(from), text.char_to_line(to))
+ }
+
/// `true` when head and anchor are at the same position.
#[inline]
pub fn is_empty(&self) -> bool {