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.
imgbot
Michael Davis 2 years ago committed by GitHub
parent 404db2ebee
commit 701cea54d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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);
};
}

Loading…
Cancel
Save