on master help sign in
Fix earlier/later missing changeset update (#1069)

Fix #1059

commit9d591427be900b7a43fc7e13dd86f31199e8c00e authorIvan Tham <pickfire@riseup.net> dateThu 11 Nov 2021, 21:32 (5 years ago) parentd131a9d
2 files changed+28−6
helix-term/src/commands.rs+8−2 helix-view/src/document.rs+20−4
helix-term/src/commands.rs+8−2
@@ -1845,7 +1845,10 @@ mod cmd {
18451845 .map_err(|s| anyhow!(s))?;
18461846
18471847 let (view, doc) = current!(cx.editor);
1848− doc.earlier(view.id, uk);
1848+ let success = doc.earlier(view.id, uk);
1849+ if !success {
1850+ cx.editor.set_status("Already at oldest change".to_owned());
1851+ }
18491852
18501853 Ok(())
18511854 }
@@ -1860,7 +1863,10 @@ mod cmd {
18601863 .parse::<helix_core::history::UndoKind>()
18611864 .map_err(|s| anyhow!(s))?;
18621865 let (view, doc) = current!(cx.editor);
1863− doc.later(view.id, uk);
1866+ let success = doc.later(view.id, uk);
1867+ if !success {
1868+ cx.editor.set_status("Already at newest change".to_owned());
1869+ }
18641870
18651871 Ok(())
18661872 }
helix-view/src/document.rs+20−4
@@ -751,19 +751,35 @@ impl Document {
751751 }
752752
753753 /// Undo modifications to the [`Document`] according to `uk`.
754− pub fn earlier(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) {
754+ pub fn earlier(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) -> bool {
755755 let txns = self.history.get_mut().earlier(uk);
756+ let mut success = false;
756757 for txn in txns {
757− self.apply_impl(&txn, view_id);
758+ if self.apply_impl(&txn, view_id) {
759+ success = true;
760+ }
761+ }
762+ if success {
763+ // reset changeset to fix len
764+ self.changes = ChangeSet::new(self.text());
758765 }
766+ success
759767 }
760768
761769 /// Redo modifications to the [`Document`] according to `uk`.
762− pub fn later(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) {
770+ pub fn later(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) -> bool {
763771 let txns = self.history.get_mut().later(uk);
772+ let mut success = false;
764773 for txn in txns {
765− self.apply_impl(&txn, view_id);
774+ if self.apply_impl(&txn, view_id) {
775+ success = true;
776+ }
777+ }
778+ if success {
779+ // reset changeset to fix len
780+ self.changes = ChangeSet::new(self.text());
766781 }
782+ success
767783 }
768784
769785 /// Commit pending changes to history