mirror of
https://github.com/helix-editor/helix.git
synced 2024-09-11 18:58:00 +03:00
address clippy warnings
This commit is contained in:
parent
23109f1512
commit
b5c38812e9
@ -3,6 +3,9 @@
|
||||
mod state;
|
||||
mod transaction;
|
||||
|
||||
pub use ropey::Rope;
|
||||
pub use tendril::StrTendril as Tendril;
|
||||
|
||||
pub use buffer::Buffer;
|
||||
|
||||
pub use selection::Range as SelectionRange;
|
||||
|
@ -30,12 +30,14 @@ pub fn new(anchor: usize, head: usize) -> Self {
|
||||
|
||||
/// Start of the range.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn from(&self) -> usize {
|
||||
std::cmp::min(self.anchor, self.head)
|
||||
}
|
||||
|
||||
/// End of the range.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn to(&self) -> usize {
|
||||
std::cmp::max(self.anchor, self.head)
|
||||
}
|
||||
@ -47,6 +49,7 @@ pub fn is_empty(&self) -> bool {
|
||||
}
|
||||
|
||||
/// Check two ranges for overlap.
|
||||
#[must_use]
|
||||
pub fn overlaps(&self, other: &Self) -> bool {
|
||||
// cursor overlap is checked differently
|
||||
if self.is_empty() {
|
||||
@ -59,6 +62,7 @@ pub fn overlaps(&self, other: &Self) -> bool {
|
||||
// TODO: map
|
||||
|
||||
/// Extend the range to cover at least `from` `to`.
|
||||
#[must_use]
|
||||
pub fn extend(&self, from: usize, to: usize) -> Self {
|
||||
if from <= self.anchor && to >= self.anchor {
|
||||
return Range {
|
||||
@ -90,12 +94,14 @@ pub struct Selection {
|
||||
impl Selection {
|
||||
// map
|
||||
// eq
|
||||
|
||||
#[must_use]
|
||||
pub fn primary(&self) -> Range {
|
||||
self.ranges[self.primary_index]
|
||||
}
|
||||
|
||||
/// Ensure selection containing only the primary selection.
|
||||
pub fn as_single(self) -> Self {
|
||||
pub fn into_single(self) -> Self {
|
||||
if self.ranges.len() == 1 {
|
||||
self
|
||||
} else {
|
||||
@ -109,6 +115,7 @@ pub fn as_single(self) -> Self {
|
||||
// add_range // push
|
||||
// replace_range
|
||||
|
||||
#[must_use]
|
||||
/// Constructs a selection holding a single range.
|
||||
pub fn single(anchor: usize, head: usize) -> Self {
|
||||
Self {
|
||||
@ -117,11 +124,12 @@ pub fn single(anchor: usize, head: usize) -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new(ranges: SmallVec<[Range; 1]>, primary_index: usize) -> Self {
|
||||
fn normalize(mut ranges: SmallVec<[Range; 1]>, primary_index: usize) -> Selection {
|
||||
fn normalize(mut ranges: SmallVec<[Range; 1]>, mut primary_index: usize) -> Selection {
|
||||
let primary = ranges[primary_index];
|
||||
ranges.sort_unstable_by_key(|range| range.from());
|
||||
let mut primary_index = ranges.iter().position(|&range| range == primary).unwrap();
|
||||
ranges.sort_unstable_by_key(Range::from);
|
||||
primary_index = ranges.iter().position(|&range| range == primary).unwrap();
|
||||
|
||||
let mut result: SmallVec<[Range; 1]> = SmallVec::new();
|
||||
|
||||
|
@ -8,6 +8,7 @@ pub struct State {
|
||||
}
|
||||
|
||||
impl State {
|
||||
#[must_use]
|
||||
pub fn new(buffer: Buffer) -> Self {
|
||||
Self {
|
||||
buffer,
|
||||
|
@ -14,10 +14,7 @@
|
||||
// distance: usize,
|
||||
// }
|
||||
|
||||
use crate::{Buffer, Selection};
|
||||
|
||||
use ropey::Rope;
|
||||
use tendril::StrTendril as Tendril;
|
||||
use crate::{Buffer, Rope, Selection, Tendril};
|
||||
|
||||
// TODO: divided into three different operations, I sort of like having just
|
||||
// Splice { extent, Option<text>, distance } better.
|
||||
@ -56,6 +53,7 @@ pub struct ChangeSet {
|
||||
}
|
||||
|
||||
impl ChangeSet {
|
||||
#[must_use]
|
||||
pub fn new(buf: &Buffer) -> Self {
|
||||
let len = buf.contents.len_chars();
|
||||
Self {
|
||||
@ -105,8 +103,7 @@ pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
|
||||
head_a = a;
|
||||
head_b = changes_b.next();
|
||||
}
|
||||
(None, _) => return Err(()),
|
||||
(_, None) => return Err(()),
|
||||
(None, _) | (_, None) => return Err(()),
|
||||
(Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
|
||||
Ordering::Less => {
|
||||
changes.push(Retain(i));
|
||||
@ -221,7 +218,7 @@ pub fn apply(&self, text: &mut Rope) {
|
||||
|
||||
let mut pos = 0;
|
||||
|
||||
for change in self.changes.iter() {
|
||||
for change in &self.changes {
|
||||
use Change::*;
|
||||
match change {
|
||||
Retain(n) => {
|
||||
|
Loading…
Reference in New Issue
Block a user