mirror of
https://github.com/helix-editor/helix
synced 2024-06-07 21:56:04 +02:00
Avoid collect() by accepting iterators into Transaction::change.
This commit is contained in:
parent
2027f69eae
commit
0427acd18c
|
@ -155,7 +155,7 @@ pub fn open_below(state: &mut State, _count: usize) {
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
let transaction = Transaction::change(state, changes.collect()).with_selection(selection);
|
let transaction = Transaction::change(state, changes).with_selection(selection);
|
||||||
|
|
||||||
transaction.apply(state);
|
transaction.apply(state);
|
||||||
// TODO: need to store into history if successful
|
// TODO: need to store into history if successful
|
||||||
|
|
|
@ -353,8 +353,10 @@ pub fn with_selection(mut self, selection: Selection) -> Self {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a transaction from a set of changes.
|
/// Generate a transaction from a set of changes.
|
||||||
// TODO: take an owned iter instead of Vec
|
pub fn change<I>(state: &State, changes: I) -> Self
|
||||||
pub fn change(state: &State, changes: Vec<Change>) -> Self {
|
where
|
||||||
|
I: IntoIterator<Item = Change> + ExactSizeIterator,
|
||||||
|
{
|
||||||
let len = state.doc.len_chars();
|
let len = state.doc.len_chars();
|
||||||
let mut acc = Vec::with_capacity(2 * changes.len() + 1);
|
let mut acc = Vec::with_capacity(2 * changes.len() + 1);
|
||||||
|
|
||||||
|
@ -381,7 +383,7 @@ pub fn change_by_selection<F>(state: &State, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(&SelectionRange) -> Change,
|
F: Fn(&SelectionRange) -> Change,
|
||||||
{
|
{
|
||||||
Self::change(state, state.selection.ranges.iter().map(f).collect())
|
Self::change(state, state.selection.ranges.iter().map(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert text at each selection head.
|
/// Insert text at each selection head.
|
||||||
|
|
Loading…
Reference in New Issue