aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/history.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-31 06:45:18 +0000
committerBlaž Hrastnik2021-03-31 06:45:18 +0000
commit9eaef6e33376407931162780cd402297c44f26c4 (patch)
treeda14993d99a50f502113befcd0f78538f4e7c716 /helix-core/src/history.rs
parentdfc17becd56efbc1f65de7c8d65cb32ad4690db1 (diff)
Fully drop State references.
Diffstat (limited to 'helix-core/src/history.rs')
-rw-r--r--helix-core/src/history.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs
index 13a2a020..df4b9fc4 100644
--- a/helix-core/src/history.rs
+++ b/helix-core/src/history.rs
@@ -33,7 +33,10 @@ impl Default for History {
impl History {
pub fn commit_revision(&mut self, transaction: &Transaction, original: &State) {
// TODO: could store a single transaction, if deletes also stored the text they delete
- let revert = transaction.invert(original);
+ let revert = transaction
+ .invert(&original.doc)
+ // Store the current cursor position
+ .with_selection(original.selection.clone());
let new_cursor = self.revisions.len();
self.revisions.push(Revision {
@@ -100,7 +103,7 @@ mod test {
// Need to commit before applying!
history.commit_revision(&transaction1, &state);
- transaction1.apply(&mut state);
+ transaction1.apply(&mut state.doc);
assert_eq!("hello world!", state.doc);
// ---
@@ -110,18 +113,18 @@ mod test {
// Need to commit before applying!
history.commit_revision(&transaction2, &state);
- transaction2.apply(&mut state);
+ transaction2.apply(&mut state.doc);
assert_eq!("hello 世界!", state.doc);
// ---
fn undo(history: &mut History, state: &mut State) {
if let Some(transaction) = history.undo() {
- transaction.apply(state);
+ transaction.apply(&mut state.doc);
}
}
fn redo(history: &mut History, state: &mut State) {
if let Some(transaction) = history.redo() {
- transaction.apply(state);
+ transaction.apply(&mut state.doc);
}
}