diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 8a8702b9cc6aa..2b07bd8f7f3b1 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -54,7 +54,7 @@ pub struct History { } /// A single point in history. See [History] for more information. -#[derive(Debug)] +#[derive(Debug, Clone)] struct Revision { parent: usize, last_child: Option, @@ -126,15 +126,13 @@ impl History { return None; } - let mut transaction = self.revisions[revision].transaction.clone(); - // The bounds are checked in the if condition above: - // `revision + 1` is known to be `<= self.current`. - for revision in &self.revisions[revision + 1..self.current] { - transaction = transaction.compose(revision.transaction.clone()); - } - - Some(transaction) + // `revision` is known to be `< self.current`. + self.revisions[revision..self.current] + .iter() + .cloned() + .map(|revision| revision.transaction) + .reduce(|acc, transaction| acc.compose(transaction)) } /// Undo the last edit.