diff options
author | Michael Davis | 2022-11-23 03:28:49 +0000 |
---|---|---|
committer | GitHub | 2022-11-23 03:28:49 +0000 |
commit | 42e37a571e75aaf4feb1717dfebe8cf215e535dd (patch) | |
tree | 385e494b1d10ce6d40b59162dae0b059d4eeb583 /helix-core/src | |
parent | 642a961c032b2a7e7fa67bfc3da54588d0ae8c5b (diff) |
Apply transactions to all views (#4733)
* Add a test case for updating jumplists across windows
* Apply transactions to all views on history changes
This ensures that jumplist selections follow changes in documents, even
when there are multiple views (for example a split where both windows
edit the same document).
* Leave TODOs for cleaning up View::apply
* Use Iterator::reduce to compose history transactions
Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
Diffstat (limited to 'helix-core/src')
-rw-r--r-- | helix-core/src/history.rs | 18 |
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() { |