From b765c17896632e27857c7707a9d3d96bd49b8899 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Tue, 6 Oct 2020 14:44:18 +0900 Subject: Hacky undo/redo integration. --- helix-core/src/state.rs | 6 +++++- helix-core/src/transaction.rs | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'helix-core/src') diff --git a/helix-core/src/state.rs b/helix-core/src/state.rs index 9d51c8c5..ed0df9cf 100644 --- a/helix-core/src/state.rs +++ b/helix-core/src/state.rs @@ -1,6 +1,6 @@ use crate::graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary, RopeGraphemes}; use crate::syntax::LOADER; -use crate::{Position, Range, Rope, RopeSlice, Selection, Syntax}; +use crate::{ChangeSet, Position, Range, Rope, RopeSlice, Selection, Syntax}; use anyhow::Error; use std::path::PathBuf; @@ -25,6 +25,8 @@ pub struct State { // pub syntax: Option, + pub changes: Option, + pub old_state: Option<(Rope, Selection)>, } #[derive(Copy, Clone, PartialEq, Eq)] @@ -50,6 +52,8 @@ impl State { mode: Mode::Normal, restore_cursor: false, syntax: None, + changes: None, + old_state: None, } } diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index d6b151ba..7871052a 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -369,6 +369,13 @@ impl Transaction { return false; } + // Compose this transaction with the previous one + let old_changes = state.changes.take(); + state.changes = Some(old_changes.map_or_else( + || self.changes.clone(), + |changes| changes.compose(self.changes.clone()).unwrap(), + )); + if let Some(syntax) = &mut state.syntax { // TODO: no unwrap syntax.update(&old_doc, &state.doc, &self.changes).unwrap(); -- cgit v1.2.3-70-g09d2