aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-12-21 04:42:47 +0000
committerBlaž Hrastnik2020-12-21 04:42:47 +0000
commitd1810272257f597ddba4fd3496dbdde8cda59638 (patch)
tree8ae867c3706ff4449f1672fac6788a7124854558 /helix-view
parent3f0dbfcac878131167953b6f57c923a5bc889e80 (diff)
fix: undo/redo selection handling.
Diffstat (limited to 'helix-view')
-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() {