From 52f5a4228aef2d31cf20aeee2bed317ba1767c18 Mon Sep 17 00:00:00 2001 From: Matouš Dzivjak Date: Wed, 27 Apr 2022 18:14:46 +0200 Subject: feat(commands): better handling of buffer-close (#1397) * feat(commands): better handling of buffer-close Previously, when closing buffer, you would loose cursor position in other docs. Also, all splits where the buffer was open would be closed. This PR changes the behavior, if the view has also other buffer previously viewed it switches back to the last one instead of the view being closed. As a side effect, since the views are persisted, the cursor history is persisted as well. Fixes: https://github.com/helix-editor/helix/issues/1186 * Adjust buffer close behavior * Remove closed documents from jump history * Fix after rebase--- helix-term/src/commands.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index fb0940fd..8a0313ef 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2489,8 +2489,8 @@ fn goto_last_line(cx: &mut Context) { } fn goto_last_accessed_file(cx: &mut Context) { - let alternate_file = view!(cx.editor).last_accessed_doc; - if let Some(alt) = alternate_file { + let view = view_mut!(cx.editor); + if let Some(alt) = view.docs_access_history.pop() { cx.editor.switch(alt, Action::Replace); } else { cx.editor.set_error("no last accessed buffer") @@ -3796,10 +3796,6 @@ fn jump_backward(cx: &mut Context) { let (view, doc) = current!(cx.editor); 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) = current!(cx.editor); // refetch doc -- cgit v1.2.3-70-g09d2