on master help sign in
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`

commit51b4d35dce92fa7bf85780cb2ba0e531db378448 authorOmnikar <omnikar5@gmail.com> dateThu 4 Nov 2021, 21:20 (5 years ago) parentaa4d0b4
2 files changed+14−6
helix-term/src/commands.rs+8−2 helix-view/src/document.rs+6−4
helix-term/src/commands.rs+8−2
@@ -3679,13 +3679,19 @@ pub mod insert {
36793679fn undo(cx: &mut Context) {
36803680 let (view, doc) = current!(cx.editor);
36813681 let view_id = view.id;
3682− doc.undo(view_id);
3682+ let success = doc.undo(view_id);
3683+ if !success {
3684+ cx.editor.set_status("Already at oldest change".to_owned());
3685+ }
36833686}
36843687
36853688fn redo(cx: &mut Context) {
36863689 let (view, doc) = current!(cx.editor);
36873690 let view_id = view.id;
3688− doc.redo(view_id);
3691+ let success = doc.redo(view_id);
3692+ if !success {
3693+ cx.editor.set_status("Already at newest change".to_owned());
3694+ }
36893695}
36903696
36913697// Yank / Paste
helix-view/src/document.rs+6−4
@@ -704,8 +704,8 @@ impl Document {
704704 success
705705 }
706706
707− /// Undo the last modification to the [`Document`].
708− pub fn undo(&mut self, view_id: ViewId) {
707+ /// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
708+ pub fn undo(&mut self, view_id: ViewId) -> bool {
709709 let mut history = self.history.take();
710710 let success = if let Some(transaction) = history.undo() {
711711 self.apply_impl(transaction, view_id)
@@ -718,10 +718,11 @@ impl Document {
718718 // reset changeset to fix len
719719 self.changes = ChangeSet::new(self.text());
720720 }
721+ success
721722 }
722723
723− /// Redo the last modification to the [`Document`].
724− pub fn redo(&mut self, view_id: ViewId) {
724+ /// Redo the last modification to the [`Document`]. Returns whether the redo was sucessful.
725+ pub fn redo(&mut self, view_id: ViewId) -> bool {
725726 let mut history = self.history.take();
726727 let success = if let Some(transaction) = history.redo() {
727728 self.apply_impl(transaction, view_id)
@@ -734,6 +735,7 @@ impl Document {
734735 // reset changeset to fix len
735736 self.changes = ChangeSet::new(self.text());
736737 }
738+ success
737739 }
738740
739741 pub fn savepoint(&mut self) {