Skip to content

Commit

Permalink
When view closes, focus on previous view
Browse files Browse the repository at this point in the history
  • Loading branch information
wes adams committed Nov 16, 2022
1 parent fe11ae2 commit d90ec9a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion helix-view/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Tree {

if self.focus == index {
// focus on something else
self.focus_next();
self.focus_prev();
}

stack.push(index);
Expand Down Expand Up @@ -521,6 +521,24 @@ impl Tree {
Some(child_id)
}

pub fn focus_prev(&mut self) {
let pos = self.traverse().position(|(id, _view)| id == self.focus);

if let Some(pos) = pos {
if pos > 0 {
match self.traverse().nth(pos - 1) {
Some((id, _view)) => self.focus = id,
None => {
let (key, _) = self.traverse().next().unwrap();
self.focus = key;
}
}
} else {
self.focus_next();
}
}
}

pub fn focus_next(&mut self) {
// This function is very dumb, but that's because we don't store any parent links.
// (we'd be able to go parent.next_sibling() recursively until we find something)
Expand Down

0 comments on commit d90ec9a

Please # to comment.