pub struct Selection { /* private fields */ }
Expand description
A selection holding one or more SelRegion
.
Regions are kept in order from the leftmost selection to the rightmost selection.
Implementations§
Source§impl Selection
impl Selection
Sourcepub fn sel_region(region: SelRegion) -> Self
pub fn sel_region(region: SelRegion) -> Self
Sourcepub fn contains(&self, offset: usize) -> bool
pub fn contains(&self, offset: usize) -> bool
Returns whether this Selection
, contains the given offset
position or not.
Example:
let selection = Selection::region(0, 2);
assert!(selection.contains(0));
assert!(selection.contains(1));
assert!(selection.contains(2));
assert!(!selection.contains(3));
Sourcepub fn regions_mut(&mut self) -> &mut [SelRegion]
pub fn regions_mut(&mut self) -> &mut [SelRegion]
Returns a mutable reference to this selection regions
Sourcepub fn min(&self) -> Selection
pub fn min(&self) -> Selection
Returns a copy of self
with all regions converted to caret region at their respective
SelRegion::min
offset.
Examples:
let mut selection = Selection::new();
selection.add_region(SelRegion::new(1, 3, None));
selection.add_region(SelRegion::new(6, 12, None));
selection.add_region(SelRegion::new(24, 48, None));
assert_eq!(selection.min().regions(), vec![
SelRegion::caret(1),
SelRegion::caret(6),
SelRegion::caret(24)
]);
Sourcepub fn first(&self) -> Option<&SelRegion>
pub fn first(&self) -> Option<&SelRegion>
Get the leftmost SelRegion
in this selection if present.
Sourcepub fn last(&self) -> Option<&SelRegion>
pub fn last(&self) -> Option<&SelRegion>
Get the rightmost SelRegion
in this selection if present.
Sourcepub fn last_inserted(&self) -> Option<&SelRegion>
pub fn last_inserted(&self) -> Option<&SelRegion>
Get the last inserted SelRegion
in this selection if present.
Sourcepub fn last_inserted_mut(&mut self) -> Option<&mut SelRegion>
pub fn last_inserted_mut(&mut self) -> Option<&mut SelRegion>
Get a mutable reference to the last inserted SelRegion
in this selection if present.
Sourcepub fn is_caret(&self) -> bool
pub fn is_caret(&self) -> bool
A Selection
is considered to be a caret if it contains
only caret SelRegion
(see SelRegion::is_caret
)
pub fn current_caret(&self) -> Option<usize>
Sourcepub fn min_offset(&self) -> usize
pub fn min_offset(&self) -> usize
Returns the minimal offset across all region of this selection.
This function panics if the selection is empty.
Example:
let mut selection = Selection::new();
selection.add_region(SelRegion::caret(4));
selection.add_region(SelRegion::new(0, 12, None));
selection.add_region(SelRegion::new(24, 48, None));
assert_eq!(selection.min_offset(), 0);
Sourcepub fn max_offset(&self) -> usize
pub fn max_offset(&self) -> usize
Returns the maximal offset across all region of this selection.
This function panics if the selection is empty.
Example:
let mut selection = Selection::new();
selection.add_region(SelRegion::caret(4));
selection.add_region(SelRegion::new(0, 12, None));
selection.add_region(SelRegion::new(24, 48, None));
assert_eq!(selection.max_offset(), 48);
Sourcepub fn regions_in_range(&self, start: usize, end: usize) -> &[SelRegion]
pub fn regions_in_range(&self, start: usize, end: usize) -> &[SelRegion]
Returns regions in self
overlapping or fully enclosed in the provided
start
to end
range.
Example:
let mut selection = Selection::new();
selection.add_region(SelRegion::new(0, 3, None));
selection.add_region(SelRegion::new(3, 6, None));
selection.add_region(SelRegion::new(7, 8, None));
selection.add_region(SelRegion::new(9, 11, None));
let regions = selection.regions_in_range(5, 10);
assert_eq!(regions, vec![
SelRegion::new(3, 6, None),
SelRegion::new(7, 8, None),
SelRegion::new(9, 11, None)
]);
Sourcepub fn full_regions_in_range(&self, start: usize, end: usize) -> &[SelRegion]
pub fn full_regions_in_range(&self, start: usize, end: usize) -> &[SelRegion]
Returns regions in self
starting between start
to end
range.
Example:
let mut selection = Selection::new();
selection.add_region(SelRegion::new(0, 3, None));
selection.add_region(SelRegion::new(3, 6, None));
selection.add_region(SelRegion::new(7, 8, None));
selection.add_region(SelRegion::new(9, 11, None));
let regions = selection.full_regions_in_range(5, 10);
assert_eq!(regions, vec![
SelRegion::new(7, 8, None),
SelRegion::new(9, 11, None)
]);
Sourcepub fn delete_range(&mut self, start: usize, end: usize)
pub fn delete_range(&mut self, start: usize, end: usize)
Deletes regions in self
overlapping or enclosing in start
to end
range.
Example:
let mut selection = Selection::new();
selection.add_region(SelRegion::new(0, 3, None));
selection.add_region(SelRegion::new(3, 6, None));
selection.add_region(SelRegion::new(7, 8, None));
selection.add_region(SelRegion::new(9, 11, None));
selection.delete_range(5, 10);
assert_eq!(selection.regions(), vec![SelRegion::new(0, 3, None)]);
Sourcepub fn add_region(&mut self, region: SelRegion)
pub fn add_region(&mut self, region: SelRegion)
Add a regions to self
. Note that if provided region overlap
on of the selection regions they will be merged in a single region.
Example:
let mut selection = Selection::new();
// Overlapping
selection.add_region(SelRegion::new(0, 4, None));
selection.add_region(SelRegion::new(3, 6, None));
assert_eq!(selection.regions(), vec![SelRegion::new(0, 6, None)]);
// Non-overlapping
let mut selection = Selection::new();
selection.add_region(SelRegion::new(0, 3, None));
selection.add_region(SelRegion::new(3, 6, None));
assert_eq!(selection.regions(), vec![
SelRegion::new(0, 3, None),
SelRegion::new(3, 6, None)
]);
Sourcepub fn add_range_distinct(&mut self, region: SelRegion) -> (usize, usize)
pub fn add_range_distinct(&mut self, region: SelRegion) -> (usize, usize)
Add a region to the selection. This method does not merge regions and does not allow ambiguous regions (regions that overlap).
On ambiguous regions, the region with the lower start position wins. That is, in such a case, the new region is either not added at all, because there is an ambiguous region with a lower start position, or existing regions that intersect with the new region but do not start before the new region, are deleted.
Sourcepub fn apply_delta(
&self,
delta: &RopeDelta,
after: bool,
drift: InsertDrift,
) -> Selection
pub fn apply_delta( &self, delta: &RopeDelta, after: bool, drift: InsertDrift, ) -> Selection
Apply [lapce_xi_rope::RopeDelta
] to this selection.
Typically used to apply an edit to a buffer and update its selections
Parameters:
delta
[lapce_xi_rope::RopeDelta
]after
parameter indicate if the delta should be applied before or after the selectiondrift
seeInsertDrift
Sourcepub fn get_cursor_offset(&self) -> usize
pub fn get_cursor_offset(&self) -> usize
Returns cursor position, which corresponds to last inserted region end
offset,
Sourcepub fn replace_last_inserted_region(&mut self, region: SelRegion)
pub fn replace_last_inserted_region(&mut self, region: SelRegion)
Replaces last inserted SelRegion
of this selection with the provided one.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Selection
impl<'de> Deserialize<'de> for Selection
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Selection
Auto Trait Implementations§
impl Freeze for Selection
impl RefUnwindSafe for Selection
impl Send for Selection
impl Sync for Selection
impl Unpin for Selection
impl UnwindSafe for Selection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more