diff options
author | Robin | 2021-06-12 12:21:06 +0000 |
---|---|---|
committer | GitHub | 2021-06-12 12:21:06 +0000 |
commit | 44cc0d8eb0743101724fca8787217a9d0aa01bd4 (patch) | |
tree | 388d4b85779f3ebb6e8c8489b563bd05237720f5 /helix-term | |
parent | 19535888735a97e0a9ccb057ea12f8bbd4dfaa7a (diff) |
add alternate file (#223)
* add alternate file
inspired by vim ctrl-6/kak ga commands. the alternate file is kept per view
* apply feedback from #223
* rename to last_accessed
* add ga doc
* add fail message for ga
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index f9db5581..0ae2186b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1317,6 +1317,15 @@ fn push_jump(editor: &mut Editor) { view.jumps.push(jump); } +fn switch_to_last_accessed_file(cx: &mut Context) { + let alternate_file = cx.view().last_accessed_doc; + if let Some(alt) = alternate_file { + cx.editor.switch(alt, Action::Replace); + } else { + cx.editor.set_error("no last buffer".to_owned()) + } +} + pub fn goto_mode(cx: &mut Context) { if let Some(count) = cx._count { push_jump(cx.editor); @@ -1338,6 +1347,7 @@ pub fn goto_mode(cx: &mut Context) { match (cx.doc().mode, ch) { (_, 'g') => move_file_start(cx), (_, 'e') => move_file_end(cx), + (_, 'a') => switch_to_last_accessed_file(cx), (Mode::Normal, 'h') => move_line_start(cx), (Mode::Normal, 'l') => move_line_end(cx), (Mode::Select, 'h') => extend_line_start(cx), @@ -2449,6 +2459,10 @@ pub fn jump_backward(cx: &mut Context) { let (view, doc) = cx.current(); if let Some((id, selection)) = view.jumps.backward(view.id, doc, count) { + // manually set the alternate_file as we cannot use the Editor::switch function here. + if view.doc != *id { + view.last_accessed_doc = Some(view.doc) + } view.doc = *id; let selection = selection.clone(); let (view, doc) = cx.current(); // refetch doc |