Inform when reaching undo/redo bounds (#981)

* Inform when reaching undo/redo bounds

* `Already at oldest change` when undo fails
* `Already at newest change` when redo fails

* Add missing `the`
pull/984/head
Omnikar 3 years ago committed by GitHub
parent aa4d0b4646
commit 51b4d35dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3679,13 +3679,19 @@ pub mod insert {
fn undo(cx: &mut Context) { fn undo(cx: &mut Context) {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
let view_id = view.id; let view_id = view.id;
doc.undo(view_id); let success = doc.undo(view_id);
if !success {
cx.editor.set_status("Already at oldest change".to_owned());
}
} }
fn redo(cx: &mut Context) { fn redo(cx: &mut Context) {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
let view_id = view.id; let view_id = view.id;
doc.redo(view_id); let success = doc.redo(view_id);
if !success {
cx.editor.set_status("Already at newest change".to_owned());
}
} }
// Yank / Paste // Yank / Paste

@ -704,8 +704,8 @@ impl Document {
success success
} }
/// Undo the last modification to the [`Document`]. /// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
pub fn undo(&mut self, view_id: ViewId) { pub fn undo(&mut self, view_id: ViewId) -> bool {
let mut history = self.history.take(); let mut history = self.history.take();
let success = if let Some(transaction) = history.undo() { let success = if let Some(transaction) = history.undo() {
self.apply_impl(transaction, view_id) self.apply_impl(transaction, view_id)
@ -718,10 +718,11 @@ impl Document {
// reset changeset to fix len // reset changeset to fix len
self.changes = ChangeSet::new(self.text()); self.changes = ChangeSet::new(self.text());
} }
success
} }
/// Redo the last modification to the [`Document`]. /// Redo the last modification to the [`Document`]. Returns whether the redo was sucessful.
pub fn redo(&mut self, view_id: ViewId) { pub fn redo(&mut self, view_id: ViewId) -> bool {
let mut history = self.history.take(); let mut history = self.history.take();
let success = if let Some(transaction) = history.redo() { let success = if let Some(transaction) = history.redo() {
self.apply_impl(transaction, view_id) self.apply_impl(transaction, view_id)
@ -734,6 +735,7 @@ impl Document {
// reset changeset to fix len // reset changeset to fix len
self.changes = ChangeSet::new(self.text()); self.changes = ChangeSet::new(self.text());
} }
success
} }
pub fn savepoint(&mut self) { pub fn savepoint(&mut self) {

Loading…
Cancel
Save