diff options
Diffstat (limited to 'helix-core/src/selection.rs')
-rw-r--r-- | helix-core/src/selection.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index 3463c1d3..1f28ecef 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -122,7 +122,7 @@ impl Range { } } - // flips the direction of the selection + /// Flips the direction of the selection pub fn flip(&self) -> Self { Self { anchor: self.head, @@ -131,6 +131,16 @@ impl Range { } } + /// Returns the selection if it goes in the direction of `direction`, + /// flipping the selection otherwise. + pub fn with_direction(self, direction: Direction) -> Self { + if self.direction() == direction { + self + } else { + self.flip() + } + } + /// Check two ranges for overlap. #[must_use] pub fn overlaps(&self, other: &Self) -> bool { |