Skip to content

Commit

Permalink
Remove dependency on itertools
Browse files Browse the repository at this point in the history
  • Loading branch information
sireliah committed Nov 29, 2022
1 parent 627031e commit 92756f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ helix-loader = { version = "0.6", path = "../helix-loader" }

anyhow = "1"
once_cell = "1.16"
itertools = "0.10.5"

which = "4.2"

Expand Down
35 changes: 11 additions & 24 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ use serde::de::{self, Deserialize, Deserializer};
use grep_regex::RegexMatcherBuilder;
use grep_searcher::{sinks, BinaryDetection, SearcherBuilder};
use ignore::{DirEntry, WalkBuilder, WalkState};
use itertools::FoldWhile::{Continue, Done};
use itertools::Itertools;
use tokio_stream::wrappers::UnboundedReceiverStream;

pub struct Context<'a> {
Expand Down Expand Up @@ -5042,30 +5040,19 @@ fn move_selection(cx: &mut Context, direction: MoveSelection) {
// which would make the transaction to panic.
// Conflicts are resolved by picking only the top change in such case.
fn remove_conflicts(changes: Vec<Change>) -> Vec<Change> {
if changes.len() > 2 {
changes
.into_iter()
.fold_while(vec![], |mut acc: Vec<Change>, change| {
if let Some(last_change) = acc.pop() {
if last_change.0 >= change.0 || last_change.1 >= change.1 {
acc.push(last_change);
Done(acc)
} else {
acc.push(last_change);
acc.push(change);
Continue(acc)
}
} else {
acc.push(change);
Continue(acc)
}
})
.into_inner()
} else {
changes
let mut new_changes: Vec<Change> = Vec::new();
for change in changes {
match new_changes.last() {
Some(last_change) if last_change.0 >= change.0 || last_change.1 >= change.1 => {
return new_changes;
}
_ => new_changes.push(change.clone()),
}
}

new_changes
}
let flat: Vec<Change> = all_changes.into_iter().flatten().unique().collect();
let flat: Vec<Change> = all_changes.into_iter().flatten().collect();
let filtered = remove_conflicts(flat);

let new_selection = selection.clone().transform(|range| {
Expand Down

0 comments on commit 92756f3

Please # to comment.