Clean up a few selection methods (#1403)

This commit is contained in:
Dániel Buga 2022-09-30 20:58:12 +02:00 committed by GitHub
parent 038145070e
commit bd7701ed82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 22 deletions

View File

@ -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