Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix earlier/later missing changeset update #1069

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,10 @@ mod cmd {
.map_err(|s| anyhow!(s))?;

let (view, doc) = current!(cx.editor);
doc.earlier(view.id, uk);
let success = doc.earlier(view.id, uk);
if !success {
cx.editor.set_status("Already at oldest change".to_owned());
}

Ok(())
}
Expand All @@ -1857,7 +1860,10 @@ mod cmd {
.parse::<helix_core::history::UndoKind>()
.map_err(|s| anyhow!(s))?;
let (view, doc) = current!(cx.editor);
doc.later(view.id, uk);
let success = doc.later(view.id, uk);
if !success {
cx.editor.set_status("Already at newest change".to_owned());
}

Ok(())
}
Expand Down
24 changes: 20 additions & 4 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,19 +751,35 @@ impl Document {
}

/// Undo modifications to the [`Document`] according to `uk`.
pub fn earlier(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) {
pub fn earlier(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) -> bool {
let txns = self.history.get_mut().earlier(uk);
let mut success = false;
for txn in txns {
self.apply_impl(&txn, view_id);
if self.apply_impl(&txn, view_id) {
success = true;
}
}
if success {
// reset changeset to fix len
self.changes = ChangeSet::new(self.text());
}
success
}

/// Redo modifications to the [`Document`] according to `uk`.
pub fn later(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) {
pub fn later(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) -> bool {
let txns = self.history.get_mut().later(uk);
let mut success = false;
for txn in txns {
self.apply_impl(&txn, view_id);
if self.apply_impl(&txn, view_id) {
success = true;
}
}
if success {
// reset changeset to fix len
self.changes = ChangeSet::new(self.text());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

}
success
}

/// Commit pending changes to history
Expand Down