fix change -> change -> undo -> change -> undo -> undo.
This commit is contained in:
parent
d181027225
commit
ea502c8665
@ -660,21 +660,15 @@ pub fn insert_char_prompt(prompt: &mut Prompt, c: char) {
|
|||||||
|
|
||||||
// Undo / Redo
|
// Undo / Redo
|
||||||
|
|
||||||
pub fn undo(cx: &mut Context) {
|
// TODO: each command could simply return a Option<transaction>, then the higher level handles
|
||||||
if let Some(revert) = cx.view.doc.history.undo() {
|
// storing it?
|
||||||
cx.view.doc.version += 1;
|
|
||||||
cx.view.doc.apply(&revert);
|
|
||||||
// TODO: undo/redo needs to avoid storing in self.changes/self.old_state
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: each command could simply return a Option<transaction>, then the higher level handles storing it?
|
pub fn undo(cx: &mut Context) {
|
||||||
|
cx.view.doc.undo();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn redo(cx: &mut Context) {
|
pub fn redo(cx: &mut Context) {
|
||||||
if let Some(transaction) = cx.view.doc.history.redo() {
|
cx.view.doc.redo();
|
||||||
cx.view.doc.version += 1;
|
|
||||||
cx.view.doc.apply(&transaction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yank / Paste
|
// Yank / Paste
|
||||||
|
@ -185,6 +185,50 @@ pub fn apply(&mut self, transaction: &Transaction) -> bool {
|
|||||||
success
|
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]
|
#[inline]
|
||||||
pub fn mode(&self) -> Mode {
|
pub fn mode(&self) -> Mode {
|
||||||
self.mode
|
self.mode
|
||||||
|
Loading…
Reference in New Issue
Block a user