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

Inform when reaching undo/redo bounds #981

Merged
merged 2 commits into from
Nov 5, 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 @@ -3679,13 +3679,19 @@ pub mod insert {
fn undo(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let view_id = view.id;
doc.undo(view_id);
let success = doc.undo(view_id);
if !success {
cx.editor.set_status("Already at oldest change".to_owned());
}
}

fn redo(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let view_id = view.id;
doc.redo(view_id);
let success = doc.redo(view_id);
if !success {
cx.editor.set_status("Already at newest change".to_owned());
}
}

// Yank / Paste
Expand Down
10 changes: 6 additions & 4 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ impl Document {
success
}

/// Undo the last modification to the [`Document`].
pub fn undo(&mut self, view_id: ViewId) {
/// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
pub fn undo(&mut self, view_id: ViewId) -> bool {
let mut history = self.history.take();
let success = if let Some(transaction) = history.undo() {
self.apply_impl(transaction, view_id)
Expand All @@ -718,10 +718,11 @@ impl Document {
// reset changeset to fix len
self.changes = ChangeSet::new(self.text());
}
success
}

/// Redo the last modification to the [`Document`].
pub fn redo(&mut self, view_id: ViewId) {
/// Redo the last modification to the [`Document`]. Returns whether the redo was sucessful.
pub fn redo(&mut self, view_id: ViewId) -> bool {
let mut history = self.history.take();
let success = if let Some(transaction) = history.redo() {
self.apply_impl(transaction, view_id)
Expand All @@ -734,6 +735,7 @@ impl Document {
// reset changeset to fix len
self.changes = ChangeSet::new(self.text());
}
success
}

pub fn savepoint(&mut self) {
Expand Down