Add editor selection utilities

Also improved test that was failing during above to use marker text approach as a drive by
This commit is contained in:
Keith Simmons 2022-03-22 16:05:01 -07:00
parent 308bfa3486
commit 6a1c197c1b
2 changed files with 326 additions and 384 deletions

View file

@ -1,5 +1,5 @@
use crate::Anchor;
use crate::{rope::TextDimension, BufferSnapshot, ToOffset, ToPoint};
use crate::{rope::TextDimension, BufferSnapshot};
use std::cmp::Ordering;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
@ -36,12 +36,12 @@ impl<T: Clone> Selection<T> {
}
}
impl<T: ToOffset + ToPoint + Copy + Ord> Selection<T> {
impl<T: Copy + Ord> Selection<T> {
pub fn is_empty(&self) -> bool {
self.start == self.end
}
pub fn set_head(&mut self, head: T) {
pub fn set_head(&mut self, head: T, new_goal: SelectionGoal) {
if head.cmp(&self.tail()) < Ordering::Equal {
if !self.reversed {
self.end = self.start;
@ -55,6 +55,14 @@ impl<T: ToOffset + ToPoint + Copy + Ord> Selection<T> {
}
self.end = head;
}
self.goal = new_goal;
}
pub fn collapse_to(&mut self, point: T, new_goal: SelectionGoal) {
self.start = point;
self.end = point;
self.goal = new_goal;
self.reversed = false;
}
}