aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorIvan Tham2021-11-14 15:16:47 +0000
committerGitHub2021-11-14 15:16:47 +0000
commitb7c3877e947d95ee0fd9b1653dab6f65bb340439 (patch)
tree9f44635f172631a880373a532a10d1c1e413fe33 /helix-term
parent6fa76d9fe77d43ebc18cc78a6a1c1957d72cf59b (diff)
Add movement shortcut for history (#1088)
alt-u and alt-U
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs60
-rw-r--r--helix-term/src/keymap.rs2
2 files changed, 45 insertions, 17 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 56cc02a2..115d1789 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1,5 +1,7 @@
use helix_core::{
- comment, coords_at_pos, find_first_non_whitespace_char, find_root, graphemes, indent,
+ comment, coords_at_pos, find_first_non_whitespace_char, find_root, graphemes,
+ history::UndoKind,
+ indent,
indent::IndentStyle,
line_ending::{get_line_ending_of_str, line_end_char_index, str_is_line_ending},
match_brackets,
@@ -284,6 +286,8 @@ impl Command {
delete_word_backward, "Delete previous word",
undo, "Undo change",
redo, "Redo change",
+ earlier, "Move backward in history",
+ later, "Move forward in history",
yank, "Yank selection",
yank_joined_to_clipboard, "Join and yank selections to clipboard",
yank_main_selection_to_clipboard, "Yank main selection to clipboard",
@@ -1877,10 +1881,7 @@ mod cmd {
args: &[&str],
_event: PromptEvent,
) -> anyhow::Result<()> {
- let uk = args
- .join(" ")
- .parse::<helix_core::history::UndoKind>()
- .map_err(|s| anyhow!(s))?;
+ let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
let (view, doc) = current!(cx.editor);
let success = doc.earlier(view.id, uk);
@@ -1896,10 +1897,7 @@ mod cmd {
args: &[&str],
_event: PromptEvent,
) -> anyhow::Result<()> {
- let uk = args
- .join(" ")
- .parse::<helix_core::history::UndoKind>()
- .map_err(|s| anyhow!(s))?;
+ let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
let (view, doc) = current!(cx.editor);
let success = doc.later(view.id, uk);
if !success {
@@ -3963,20 +3961,48 @@ pub mod insert {
// storing it?
fn undo(cx: &mut Context) {
+ let count = cx.count();
let (view, doc) = current!(cx.editor);
- let view_id = view.id;
- let success = doc.undo(view_id);
- if !success {
- cx.editor.set_status("Already at oldest change".to_owned());
+ for _ in 0..count {
+ if !doc.undo(view.id) {
+ cx.editor.set_status("Already at oldest change".to_owned());
+ break;
+ }
}
}
fn redo(cx: &mut Context) {
+ let count = cx.count();
+ let (view, doc) = current!(cx.editor);
+ for _ in 0..count {
+ if !doc.redo(view.id) {
+ cx.editor.set_status("Already at newest change".to_owned());
+ break;
+ }
+ }
+}
+
+fn earlier(cx: &mut Context) {
+ let count = cx.count();
+ let (view, doc) = current!(cx.editor);
+ for _ in 0..count {
+ // rather than doing in batch we do this so get error halfway
+ if !doc.earlier(view.id, UndoKind::Steps(1)) {
+ cx.editor.set_status("Already at oldest change".to_owned());
+ break;
+ }
+ }
+}
+
+fn later(cx: &mut Context) {
+ let count = cx.count();
let (view, doc) = current!(cx.editor);
- let view_id = view.id;
- let success = doc.redo(view_id);
- if !success {
- cx.editor.set_status("Already at newest change".to_owned());
+ for _ in 0..count {
+ // rather than doing in batch we do this so get error halfway
+ if !doc.later(view.id, UndoKind::Steps(1)) {
+ cx.editor.set_status("Already at newest change".to_owned());
+ break;
+ }
}
}
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index fc9fd590..010714dc 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -582,6 +582,8 @@ impl Default for Keymaps {
"u" => undo,
"U" => redo,
+ "A-u" => earlier,
+ "A-U" => later,
"y" => yank,
// yank_all