diff options
author | Omnikar | 2021-11-05 01:20:06 +0000 |
---|---|---|
committer | GitHub | 2021-11-05 01:20:06 +0000 |
commit | 51b4d35dce92fa7bf85780cb2ba0e531db378448 (patch) | |
tree | 051cbf8343c72cf3a0dc207fcbb207e58282f201 | |
parent | aa4d0b464645b2834d7af483d17fdc11d61d994d (diff) |
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`
-rw-r--r-- | helix-term/src/commands.rs | 10 | ||||
-rw-r--r-- | helix-view/src/document.rs | 10 |
2 files changed, 14 insertions, 6 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index f16afdfe..3d134ce5 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3679,13 +3679,19 @@ pub mod insert { fn undo(cx: &mut Context) { let (view, doc) = current!(cx.editor); 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) { let (view, doc) = current!(cx.editor); 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 diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 02da4b7a..0d86143b 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -704,8 +704,8 @@ impl Document { success } - /// Undo the last modification to the [`Document`]. - pub fn undo(&mut self, view_id: ViewId) { + /// Undo the last modification to the [`Document`]. Returns whether the undo was successful. + pub fn undo(&mut self, view_id: ViewId) -> bool { let mut history = self.history.take(); let success = if let Some(transaction) = history.undo() { self.apply_impl(transaction, view_id) @@ -718,10 +718,11 @@ impl Document { // reset changeset to fix len self.changes = ChangeSet::new(self.text()); } + success } - /// Redo the last modification to the [`Document`]. - pub fn redo(&mut self, view_id: ViewId) { + /// Redo the last modification to the [`Document`]. Returns whether the redo was sucessful. + pub fn redo(&mut self, view_id: ViewId) -> bool { let mut history = self.history.take(); let success = if let Some(transaction) = history.redo() { self.apply_impl(transaction, view_id) @@ -734,6 +735,7 @@ impl Document { // reset changeset to fix len self.changes = ChangeSet::new(self.text()); } + success } pub fn savepoint(&mut self) { |