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.
|
/// Get the leftmost [`SelRegion`] in this selection if present.
|
||||||
pub fn first(&self) -> Option<&SelRegion> {
|
pub fn first(&self) -> Option<&SelRegion> {
|
||||||
if self.is_empty() {
|
self.regions.get(0)
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(&self.regions[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the rightmost [`SelRegion`] in this selection if present.
|
/// Get the rightmost [`SelRegion`] in this selection if present.
|
||||||
pub fn last(&self) -> Option<&SelRegion> {
|
pub fn last(&self) -> Option<&SelRegion> {
|
||||||
if self.is_empty() {
|
self.regions.get(self.len() - 1)
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(&self.regions[self.len() - 1])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the last inserted [`SelRegion`] in this selection if present.
|
/// Get the last inserted [`SelRegion`] in this selection if present.
|
||||||
pub fn last_inserted(&self) -> Option<&SelRegion> {
|
pub fn last_inserted(&self) -> Option<&SelRegion> {
|
||||||
if self.is_empty() {
|
self.regions.get(self.last_inserted)
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(&self.regions[self.last_inserted])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a mutable reference to the last inserted [`SelRegion`] in this selection if present.
|
/// Get a mutable reference to the last inserted [`SelRegion`] in this selection if present.
|
||||||
pub fn last_inserted_mut(&mut self) -> Option<&mut SelRegion> {
|
pub fn last_inserted_mut(&mut self) -> Option<&mut SelRegion> {
|
||||||
if self.is_empty() {
|
self.regions.get_mut(self.last_inserted)
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(&mut self.regions[self.last_inserted])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The number of [`SelRegion`] in this selection.
|
/// 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
|
/// A [`Selection`] is considered to be a caret if it contains
|
||||||
/// only caret [`SelRegion`] (see [`SelRegion::is_caret`])
|
/// only caret [`SelRegion`] (see [`SelRegion::is_caret`])
|
||||||
pub fn is_caret(&self) -> bool {
|
pub fn is_caret(&self) -> bool {
|
||||||
for region in self.regions.iter() {
|
self.regions.iter().all(|region| region.is_caret())
|
||||||
if !region.is_caret() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if `self` has zero [`SelRegion`]
|
/// 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.
|
/// Returns the minimal offset across all region of this selection.
|
||||||
///
|
///
|
||||||
|
/// This function panics if the selection is empty.
|
||||||
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -293,6 +278,8 @@ pub fn min_offset(&self) -> usize {
|
||||||
|
|
||||||
/// Returns the maximal offset across all region of this selection.
|
/// Returns the maximal offset across all region of this selection.
|
||||||
///
|
///
|
||||||
|
/// This function panics if the selection is empty.
|
||||||
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
|
Loading…
Reference in New Issue