From f5f46b1fed242f0b5a206753f7f977299fb2ff65 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Wed, 2 Jun 2021 23:47:50 +0800 Subject: 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. --- helix-core/src/history.rs | 10 ++++------ helix-core/src/transaction.rs | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'helix-core/src') 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 { + 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(¤t_revision.revert) } - pub fn redo(&mut self) -> Option { + 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 } diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index 77cb358f..e61063f0 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -415,7 +415,7 @@ impl ChangeSet { /// Transaction represents a single undoable unit of changes. Several changes can be grouped into /// a single transaction. -#[derive(Debug, Clone)] +#[derive(Debug, Default, Clone)] pub struct Transaction { changes: ChangeSet, selection: Option, -- cgit v1.2.3-70-g09d2