aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/history.rs
diff options
context:
space:
mode:
authorIvan Tham2021-06-02 15:47:50 +0000
committerIvan Tham2021-06-02 15:47:50 +0000
commitf5f46b1fed242f0b5a206753f7f977299fb2ff65 (patch)
tree3789fdb1378b76bb572a37d5cab1276aae91a8ca /helix-core/src/history.rs
parent0a6672c6261062eb13ed8c30ab2800c340e5f6ac (diff)
Separate document history into Cell
As history is used separately from the rest of the edits, separating it can avoid needless borrowing and cloning. But one need to be aware later.
Diffstat (limited to 'helix-core/src/history.rs')
-rw-r--r--helix-core/src/history.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs
index 5a9ec8de..4348ee32 100644
--- a/helix-core/src/history.rs
+++ b/helix-core/src/history.rs
@@ -65,9 +65,7 @@ impl History {
self.cursor == 0
}
- // TODO: I'd like to pass Transaction by reference but it fights with the borrowck
-
- pub fn undo(&mut self) -> Option<Transaction> {
+ pub fn undo(&mut self) -> Option<&Transaction> {
if self.at_root() {
// We're at the root of undo, nothing to do.
return None;
@@ -77,17 +75,17 @@ impl History {
self.cursor = current_revision.parent;
- Some(current_revision.revert.clone())
+ Some(&current_revision.revert)
}
- pub fn redo(&mut self) -> Option<Transaction> {
+ pub fn redo(&mut self) -> Option<&Transaction> {
let current_revision = &self.revisions[self.cursor];
// for now, simply pick the latest child (linear undo / redo)
if let Some((index, transaction)) = current_revision.children.last() {
self.cursor = *index;
- return Some(transaction.clone());
+ return Some(&transaction);
}
None
}