summaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/history.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs
index 697f29b4..5f9fa71e 100644
--- a/helix-core/src/history.rs
+++ b/helix-core/src/history.rs
@@ -122,17 +122,21 @@ impl History {
/// Returns the changes since the given revision composed into a transaction.
/// Returns None if there are no changes between the current and given revisions.
pub fn changes_since(&self, revision: usize) -> Option<Transaction> {
- if self.at_root() || self.current >= revision {
- return None;
- }
+ use std::cmp::Ordering::*;
- // The bounds are checked in the if condition above:
- // `revision` is known to be `< self.current`.
- self.revisions[revision..self.current]
- .iter()
- .map(|revision| &revision.transaction)
- .cloned()
- .reduce(|acc, transaction| acc.compose(transaction))
+ match revision.cmp(&self.current) {
+ Equal => None,
+ Greater => self.revisions[self.current + 1..=revision]
+ .iter()
+ .map(|revision| &revision.inversion)
+ .cloned()
+ .reduce(|acc, inversion| acc.compose(inversion)),
+ Less => self.revisions[revision + 1..=self.current]
+ .iter()
+ .map(|revision| &revision.transaction)
+ .cloned()
+ .reduce(|acc, transaction| acc.compose(transaction)),
+ }
}
/// Undo the last edit.