aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs10
1 files changed, 8 insertions, 2 deletions
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<State>,
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() {