aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorath32021-11-14 15:11:53 +0000
committerGitHub2021-11-14 15:11:53 +0000
commit35c974c9c49f9127da3798c9a8e49795b3c4aadc (patch)
tree13324c42b38afd053eae9c3c8016f8a00b1af377 /helix-term
parent0949a0de7fec9e11f8011693f84b1939b0a6a548 (diff)
Implement "Goto last modification" command (#1067)
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs14
-rw-r--r--helix-term/src/keymap.rs1
-rw-r--r--helix-term/src/ui/editor.rs2
3 files changed, 16 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index d5a48c5f..e37265a8 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -257,6 +257,7 @@ impl Command {
goto_window_middle, "Goto window middle",
goto_window_bottom, "Goto window bottom",
goto_last_accessed_file, "Goto last accessed file",
+ goto_last_modification, "Goto last modification",
goto_line, "Goto line",
goto_last_line, "Goto last line",
goto_first_diag, "Goto first diagnostic",
@@ -3195,6 +3196,19 @@ fn goto_last_accessed_file(cx: &mut Context) {
}
}
+fn goto_last_modification(cx: &mut Context) {
+ let (view, doc) = current!(cx.editor);
+ let pos = doc.history.get_mut().last_edit_pos();
+ let text = doc.text().slice(..);
+ if let Some(pos) = pos {
+ let selection = doc
+ .selection(view.id)
+ .clone()
+ .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
+ doc.set_selection(view.id, selection);
+ }
+}
+
fn select_mode(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index e3e01995..b14b1a6f 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -525,6 +525,7 @@ impl Default for Keymaps {
"a" => goto_last_accessed_file,
"n" => goto_next_buffer,
"p" => goto_previous_buffer,
+ "." => goto_last_modification,
},
":" => command_mode,
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index dcf87203..bcd9f8f0 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -743,7 +743,7 @@ impl EditorView {
std::num::NonZeroUsize::new(cxt.editor.count.map_or(i, |c| c.get() * 10 + i));
}
// special handling for repeat operator
- key!('.') => {
+ key!('.') if self.keymaps.pending().is_empty() => {
// first execute whatever put us into insert mode
self.last_insert.0.execute(cxt);
// then replay the inputs