on master help sign in
Inform when reaching undo/redo bounds (#981)
51b4d35Omnikar
helix-term/src/commands.rs+8−2
@@ -3679,13 +3679,19 @@ pub mod insert {
3679fn undo(cx: &mut Context) {
3679fn undo(cx: &mut Context) {
3680 let (view, doc) = current!(cx.editor);
3680 let (view, doc) = current!(cx.editor);
3681 let view_id = view.id;
3681 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+ }
3683}
3686}
3684
3687
3685fn redo(cx: &mut Context) {
3688fn redo(cx: &mut Context) {
3686 let (view, doc) = current!(cx.editor);
3689 let (view, doc) = current!(cx.editor);
3687 let view_id = view.id;
3690 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+ }
3689}
3695}
3690
3696
3691// Yank / Paste
3697// Yank / Paste
helix-view/src/document.rs+6−4
@@ -704,8 +704,8 @@ impl Document {
704 success
704 success
705 }
705 }
706
706
707− /// Undo the last modification to the [`Document`].
707+ /// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
708− pub fn undo(&mut self, view_id: ViewId) {
708+ pub fn undo(&mut self, view_id: ViewId) -> bool {
709 let mut history = self.history.take();
709 let mut history = self.history.take();
710 let success = if let Some(transaction) = history.undo() {
710 let success = if let Some(transaction) = history.undo() {
711 self.apply_impl(transaction, view_id)
711 self.apply_impl(transaction, view_id)
@@ -718,10 +718,11 @@ impl Document {
718 // reset changeset to fix len
718 // reset changeset to fix len
719 self.changes = ChangeSet::new(self.text());
719 self.changes = ChangeSet::new(self.text());
720 }
720 }
721+ success
721 }
722 }
722
723
723− /// Redo the last modification to the [`Document`].
724+ /// Redo the last modification to the [`Document`]. Returns whether the redo was sucessful.
724− pub fn redo(&mut self, view_id: ViewId) {
725+ pub fn redo(&mut self, view_id: ViewId) -> bool {
725 let mut history = self.history.take();
726 let mut history = self.history.take();
726 let success = if let Some(transaction) = history.redo() {
727 let success = if let Some(transaction) = history.redo() {
727 self.apply_impl(transaction, view_id)
728 self.apply_impl(transaction, view_id)
@@ -734,6 +735,7 @@ impl Document {
734 // reset changeset to fix len
735 // reset changeset to fix len
735 self.changes = ChangeSet::new(self.text());
736 self.changes = ChangeSet::new(self.text());
736 }
737 }
738+ success
737 }
739 }
738
740
739 pub fn savepoint(&mut self) {
741 pub fn savepoint(&mut self) {