From 701cea54d280786d5762396c5d2655cba5b508b4 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 30 Aug 2022 20:45:47 -0500 Subject: [PATCH] jumplist: Add documents to view history (#3593) This change adds documents to the view's document history Vec. (This is used by `ga` for example to access the last buffer.) Previously, a sequence like so would have confusing behavior: 1. Open file A: any document with an active language server 2. Find some definition that lives in another file - file B - with `gd` 3. Jump back in the jumplist with `C-o` to file A 4. Use `ga` intending to switch back to file B The behavior prior to this change was that `ga` would switch to file A: you could not use `ga` to switch to file B. --- helix-term/src/commands.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index cb5460afa..5bce6ca67 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4060,13 +4060,18 @@ fn match_brackets(cx: &mut Context) { fn jump_forward(cx: &mut Context) { let count = cx.count(); let view = view_mut!(cx.editor); + let doc_id = view.doc; if let Some((id, selection)) = view.jumps.forward(count) { view.doc = *id; let selection = selection.clone(); let (view, doc) = current!(cx.editor); // refetch doc - doc.set_selection(view.id, selection); + if doc.id() != doc_id { + view.add_to_history(doc_id); + } + + doc.set_selection(view.id, selection); align_view(doc, view, Align::Center); }; } @@ -4074,13 +4079,18 @@ fn jump_forward(cx: &mut Context) { fn jump_backward(cx: &mut Context) { let count = cx.count(); let (view, doc) = current!(cx.editor); + let doc_id = doc.id(); if let Some((id, selection)) = view.jumps.backward(view.id, doc, count) { view.doc = *id; let selection = selection.clone(); let (view, doc) = current!(cx.editor); // refetch doc - doc.set_selection(view.id, selection); + if doc.id() != doc_id { + view.add_to_history(doc_id); + } + + doc.set_selection(view.id, selection); align_view(doc, view, Align::Center); }; }