on master help sign in
Fix earlier/later missing changeset update (#1069)
9d59142Ivan Tham
helix-term/src/commands.rs+8−2
@@ -1845,7 +1845,10 @@ mod cmd {
1845 .map_err(|s| anyhow!(s))?;
1845 .map_err(|s| anyhow!(s))?;
1846
1846
1847 let (view, doc) = current!(cx.editor);
1847 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+ }
1849
1852
1850 Ok(())
1853 Ok(())
1851 }
1854 }
@@ -1860,7 +1863,10 @@ mod cmd {
1860 .parse::<helix_core::history::UndoKind>()
1863 .parse::<helix_core::history::UndoKind>()
1861 .map_err(|s| anyhow!(s))?;
1864 .map_err(|s| anyhow!(s))?;
1862 let (view, doc) = current!(cx.editor);
1865 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+ }
1864
1870
1865 Ok(())
1871 Ok(())
1866 }
1872 }
helix-view/src/document.rs+20−4
@@ -751,19 +751,35 @@ impl Document {
751 }
751 }
752
752
753 /// Undo modifications to the [`Document`] according to `uk`.
753 /// 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 {
755 let txns = self.history.get_mut().earlier(uk);
755 let txns = self.history.get_mut().earlier(uk);
756+ let mut success = false;
756 for txn in txns {
757 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());
758 }
765 }
766+ success
759 }
767 }
760
768
761 /// Redo modifications to the [`Document`] according to `uk`.
769 /// 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 {
763 let txns = self.history.get_mut().later(uk);
771 let txns = self.history.get_mut().later(uk);
772+ let mut success = false;
764 for txn in txns {
773 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());
766 }
781 }
782+ success
767 }
783 }
768
784
769 /// Commit pending changes to history
785 /// Commit pending changes to history