@@ -122,17 +122,21 @@ impl History {
122 /// Returns the changes since the given revision composed into a transaction.
122 /// Returns the changes since the given revision composed into a transaction.
123 /// Returns None if there are no changes between the current and given revisions.
123 /// Returns None if there are no changes between the current and given revisions.
124 pub fn changes_since(&self, revision: usize) -> Option<Transaction> {
124 pub fn changes_since(&self, revision: usize) -> Option<Transaction> {
125− if self.at_root() || self.current >= revision {
125+ use std::cmp::Ordering::*;
129− // The bounds are checked in the if condition above:
127+ match revision.cmp(&self.current) {
130− // `revision` is known to be `< self.current`.
128+ Equal => None,
129+ Greater => self.revisions[self.current + 1..=revision]
131+ .map(|revision| &revision.inversion)
133+ .reduce(|acc, inversion| acc.compose(inversion)),
131− self.revisions[revision..self.current]
134+ Less => self.revisions[revision + 1..=self.current]
133− .map(|revision| &revision.transaction)
136+ .map(|revision| &revision.transaction)
134− .cloned()
137+ .cloned()
135− .reduce(|acc, transaction| acc.compose(transaction))
138+ .reduce(|acc, transaction| acc.compose(transaction)),
138 /// Undo the last edit.
142 /// Undo the last edit.