diff options
author | Jakub Bartodziej | 2021-06-11 13:06:13 +0000 |
---|---|---|
committer | GitHub | 2021-06-11 13:06:13 +0000 |
commit | 69fe46a122f728b4bb6cb218fd410544097b0dcd (patch) | |
tree | 473dbad3d9fbd1f960f7930fcf0c2681bd780091 /helix-view/src | |
parent | 86af55c379c531df2d5dbc72841e28a10fc7938e (diff) |
Add :earlier and :later commands that can be used to navigate the full edit history. (#194)
* Disable deleting from an empty buffer which can cause a crash.
* Improve on the fix for deleting from the end of the buffer.
* Clean up leftover log.
* Avoid theoretical underflow.
* Implement :before which accepts a time interval and moves the editor to
the closest history state to the commit of the current time minus that
interval. Current time is now by default, or the commit time if :before
has just been used.
* Add :earlier an :later commands that can move through
the edit history and retrieve changes hidded by undoing
and commiting new changes. The commands accept a number
of steps or a time period relative to the currrent change.
* Fix clippy lint error.
* Remove the dependency on parse_duration, add a custom parser instead.
* Fix clippy errors.
* Make helix_core::history a public module.
* Use the helper for getting the current document and view.
* Handled some PR comments.
* Fix the logic in :later n.
Co-authored-by: Ivan Tham <pickfire@riseup.net>
* Add an alias for :earlier.
Co-authored-by: Ivan Tham <pickfire@riseup.net>
* Add an alias for later.
Co-authored-by: Ivan Tham <pickfire@riseup.net>
* Run cargo fmt.
* Add some tests for earlier and later.
* Add more tests and restore the fix for later that diappeared somehow.
* Use ? instead of a match on an option.
Co-authored-by: Ivan Tham <pickfire@riseup.net>
* Rename to UndoKind.
* Remove the leftover match.
* Handle a bunch of review comments.
* More systemd.time compliant time units and additional description for the new commands.
* A more concise rewrite of the time span parser using ideas from PR discussion.
* Replace a match with map_err().
Co-authored-by: Ivan Tham <pickfire@riseup.net>
Co-authored-by: Jakub Bartodziej <jqb@google.com>
Co-authored-by: Ivan Tham <pickfire@riseup.net>
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 6a687955..75a0e9fa 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -5,8 +5,9 @@ use std::path::{Component, Path, PathBuf}; use std::sync::Arc; use helix_core::{ + history::History, syntax::{LanguageConfiguration, LOADER}, - ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction, + ChangeSet, Diagnostic, Rope, Selection, State, Syntax, Transaction, }; use crate::{DocumentId, ViewId}; @@ -387,7 +388,7 @@ impl Document { success } - pub fn undo(&mut self, view_id: ViewId) -> bool { + pub fn undo(&mut self, view_id: ViewId) { let mut history = self.history.take(); let success = if let Some(transaction) = history.undo() { self._apply(&transaction, view_id) @@ -400,11 +401,9 @@ impl Document { // reset changeset to fix len self.changes = ChangeSet::new(self.text()); } - - success } - pub fn redo(&mut self, view_id: ViewId) -> bool { + pub fn redo(&mut self, view_id: ViewId) { let mut history = self.history.take(); let success = if let Some(transaction) = history.redo() { self._apply(&transaction, view_id) @@ -417,8 +416,20 @@ impl Document { // reset changeset to fix len self.changes = ChangeSet::new(self.text()); } + } - false + pub fn earlier(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) { + let txns = self.history.get_mut().earlier(uk); + for txn in txns { + self._apply(&txn, view_id); + } + } + + pub fn later(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) { + let txns = self.history.get_mut().later(uk); + for txn in txns { + self._apply(&txn, view_id); + } } pub fn append_changes_to_history(&mut self, view_id: ViewId) { |