mirror of https://github.com/lapce/lapce.git
Clean up a few selection methods (#1403)
This commit is contained in:
parent
038145070e
commit
bd7701ed82
|
@ -220,34 +220,22 @@ pub fn min(&self) -> Selection {
|
|||
|
||||
/// Get the leftmost [`SelRegion`] in this selection if present.
|
||||
pub fn first(&self) -> Option<&SelRegion> {
|
||||
if self.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(&self.regions[0])
|
||||
self.regions.get(0)
|
||||
}
|
||||
|
||||
/// Get the rightmost [`SelRegion`] in this selection if present.
|
||||
pub fn last(&self) -> Option<&SelRegion> {
|
||||
if self.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(&self.regions[self.len() - 1])
|
||||
self.regions.get(self.len() - 1)
|
||||
}
|
||||
|
||||
/// Get the last inserted [`SelRegion`] in this selection if present.
|
||||
pub fn last_inserted(&self) -> Option<&SelRegion> {
|
||||
if self.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(&self.regions[self.last_inserted])
|
||||
self.regions.get(self.last_inserted)
|
||||
}
|
||||
|
||||
/// Get a mutable reference to the last inserted [`SelRegion`] in this selection if present.
|
||||
pub fn last_inserted_mut(&mut self) -> Option<&mut SelRegion> {
|
||||
if self.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(&mut self.regions[self.last_inserted])
|
||||
self.regions.get_mut(self.last_inserted)
|
||||
}
|
||||
|
||||
/// The number of [`SelRegion`] in this selection.
|
||||
|
@ -258,12 +246,7 @@ pub fn len(&self) -> usize {
|
|||
/// A [`Selection`] is considered to be a caret if it contains
|
||||
/// only caret [`SelRegion`] (see [`SelRegion::is_caret`])
|
||||
pub fn is_caret(&self) -> bool {
|
||||
for region in self.regions.iter() {
|
||||
if !region.is_caret() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
self.regions.iter().all(|region| region.is_caret())
|
||||
}
|
||||
|
||||
/// Returns `true` if `self` has zero [`SelRegion`]
|
||||
|
@ -273,6 +256,8 @@ pub fn is_empty(&self) -> bool {
|
|||
|
||||
/// Returns the minimal offset across all region of this selection.
|
||||
///
|
||||
/// This function panics if the selection is empty.
|
||||
///
|
||||
/// **Example:**
|
||||
///
|
||||
/// ```rust
|
||||
|
@ -293,6 +278,8 @@ pub fn min_offset(&self) -> usize {
|
|||
|
||||
/// Returns the maximal offset across all region of this selection.
|
||||
///
|
||||
/// This function panics if the selection is empty.
|
||||
///
|
||||
/// **Example:**
|
||||
///
|
||||
/// ```rust
|
||||
|
|
Loading…
Reference in New Issue