on master help sign in
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.

commit701cea54d280786d5762396c5d2655cba5b508b4 authorMichael Davis <mcarsondavis@gmail.com> dateTue 30 Aug 2022, 20:45 (4 years ago) parent404db2e
1 file changed+12−2
helix-term/src/commands.rs+12−2
helix-term/src/commands.rs+12−2
@@ -4060,13 +4060,18 @@ fn match_brackets(cx: &mut Context) {
40604060fn jump_forward(cx: &mut Context) {
40614061 let count = cx.count();
40624062 let view = view_mut!(cx.editor);
4063+ let doc_id = view.doc;
40634064
40644065 if let Some((id, selection)) = view.jumps.forward(count) {
40654066 view.doc = *id;
40664067 let selection = selection.clone();
40674068 let (view, doc) = current!(cx.editor); // refetch doc
4068− doc.set_selection(view.id, selection);
40694069
4070+ if doc.id() != doc_id {
4071+ view.add_to_history(doc_id);
4072+ }
4073+
4074+ doc.set_selection(view.id, selection);
40704075 align_view(doc, view, Align::Center);
40714076 };
40724077}
@@ -4074,13 +4079,18 @@ fn jump_forward(cx: &mut Context) {
40744079fn jump_backward(cx: &mut Context) {
40754080 let count = cx.count();
40764081 let (view, doc) = current!(cx.editor);
4082+ let doc_id = doc.id();
40774083
40784084 if let Some((id, selection)) = view.jumps.backward(view.id, doc, count) {
40794085 view.doc = *id;
40804086 let selection = selection.clone();
40814087 let (view, doc) = current!(cx.editor); // refetch doc
4082− doc.set_selection(view.id, selection);
40834088
4089+ if doc.id() != doc_id {
4090+ view.add_to_history(doc_id);
4091+ }
4092+
4093+ doc.set_selection(view.id, selection);
40844094 align_view(doc, view, Align::Center);
40854095 };
40864096}