Skip to content

Commit

Permalink
jumplist: Add documents to view history (#3593)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-mikedavis authored Aug 31, 2022
1 parent 404db2e commit 701cea5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4060,27 +4060,37 @@ 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);
};
}

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);
};
}
Expand Down

0 comments on commit 701cea5

Please sign in to comment.