aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-12-21 04:58:54 +0000
committerBlaž Hrastnik2020-12-21 04:58:54 +0000
commitea502c8665332932b2311df3852b5ac8df6509af (patch)
treef9dc0b8183b63f803780fa8e2189dc5aeab2f52f /helix-view/src
parentd1810272257f597ddba4fd3496dbdde8cda59638 (diff)
fix change -> change -> undo -> change -> undo -> undo.
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 0dc40c5a..d6246c34 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -185,6 +185,50 @@ impl Document {
success
}
+ pub fn undo(&mut self) -> bool {
+ if let Some(transaction) = self.history.undo() {
+ let old_doc = self.text().clone();
+ self.version += 1;
+ let success = transaction.apply(&mut self.state);
+
+ // update tree-sitter syntax tree
+ if let Some(syntax) = &mut self.syntax {
+ // TODO: no unwrap
+ syntax
+ .update(&old_doc, &self.state.doc, transaction.changes())
+ .unwrap();
+ }
+
+ // reset changeset to fix len
+ self.changes = ChangeSet::new(self.text());
+
+ return success;
+ }
+ false
+ }
+
+ pub fn redo(&mut self) -> bool {
+ if let Some(transaction) = self.history.redo() {
+ let old_doc = self.text().clone();
+ self.version += 1;
+ let success = transaction.apply(&mut self.state);
+
+ // update tree-sitter syntax tree
+ if let Some(syntax) = &mut self.syntax {
+ // TODO: no unwrap
+ syntax
+ .update(&old_doc, &self.state.doc, transaction.changes())
+ .unwrap();
+ }
+
+ // reset changeset to fix len
+ self.changes = ChangeSet::new(self.text());
+
+ return success;
+ }
+ false
+ }
+
#[inline]
pub fn mode(&self) -> Mode {
self.mode