aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/history.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs
index 51174c02..697f29b4 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<NonZeroUsize>,
@@ -119,6 +119,22 @@ impl History {
self.current == 0
}
+ /// 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;
+ }
+
+ // 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))
+ }
+
/// Undo the last edit.
pub fn undo(&mut self) -> Option<&Transaction> {
if self.at_root() {