From d1810272257f597ddba4fd3496dbdde8cda59638 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 21 Dec 2020 13:42:47 +0900 Subject: fix: undo/redo selection handling. --- helix-view/src/document.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'helix-view/src') diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 323c7bff..0dc40c5a 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -30,7 +30,7 @@ pub struct Document { /// Pending changes since last history commit. pub changes: ChangeSet, - pub old_state: State, + pub old_state: Option, pub history: History, pub version: i32, // should be usize? @@ -58,7 +58,7 @@ use url::Url; impl Document { fn new(state: State) -> Self { let changes = ChangeSet::new(&state.doc); - let old_state = state.clone(); + let old_state = None; Self { path: None, @@ -156,6 +156,12 @@ impl Document { pub fn apply(&mut self, transaction: &Transaction) -> bool { let old_doc = self.text().clone(); + // store the state just before any changes are made. This allows us to undo to the + // state just before a transaction was applied. + if self.changes.is_empty() && !transaction.changes().is_empty() { + self.old_state = Some(self.state.clone()); + } + let success = transaction.apply(&mut self.state); if !transaction.changes().is_empty() { -- cgit v1.2.3-70-g09d2