diff options
author | Pascal Kuthe | 2023-04-05 18:24:49 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2023-05-18 06:16:50 +0000 |
commit | bcb8c3d34d87d97d01d37a2dda839197f2a375d8 (patch) | |
tree | 6a2c8e4f0e4cd702ab900a798f7ea1f57fe25ef2 /helix-view/src/document.rs | |
parent | 9c558fc4705934097b5f20b100462fc1fa4f50e1 (diff) |
deduplicate savepoints
Diffstat (limited to 'helix-view/src/document.rs')
-rw-r--r-- | helix-view/src/document.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index e467efd3..4d8e61e1 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1240,6 +1240,22 @@ impl Document { /// the state it had when this function was called. pub fn savepoint(&mut self, view: &View) -> Arc<SavePoint> { let revert = Transaction::new(self.text()).with_selection(self.selection(view.id).clone()); + // check if there is already an existing (identical) savepoint around + if let Some(savepoint) = self + .savepoints + .iter() + .rev() + .find_map(|savepoint| savepoint.upgrade()) + { + let transaction = savepoint.revert.lock(); + if savepoint.view == view.id + && transaction.changes().is_empty() + && transaction.selection() == revert.selection() + { + drop(transaction); + return savepoint; + } + } let savepoint = Arc::new(SavePoint { view: view.id, revert: Mutex::new(revert), |