@ -122,17 +122,21 @@ impl History {
/// Returns the changes since the given revision composed into a transaction.
/// Returns the changes since the given revision composed into a transaction.
/// Returns None if there are no changes between the current and given revisions.
/// Returns None if there are no changes between the current and given revisions.
pub fn changes_since ( & self , revision : usize ) -> Option < Transaction > {
pub fn changes_since ( & self , revision : usize ) -> Option < Transaction > {
if self . at_root ( ) | | self . current > = revision {
use std ::cmp ::Ordering ::* ;
return None ;
}
// The bounds are checked in the if condition above:
match revision . cmp ( & self . current ) {
// `revision` is known to be `< self.current`.
Equal = > None ,
self . revisions [ revision .. self . current ]
Greater = > self . revisions [ self . current + 1 ..= revision ]
. iter ( )
. iter ( )
. map ( | revision | & revision . transaction )
. map ( | revision | & revision . inversion )
. cloned ( )
. cloned ( )
. reduce ( | acc , transaction | acc . compose ( transaction ) )
. 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.
/// Undo the last edit.