@@ -219,7 +219,7 @@ impl Tree {
220 if self.focus == index {
220 if self.focus == index {
221 // focus on something else
221 // focus on something else
222− self.focus = self.next();
222+ self.focus = self.prev();
225 stack.push(index);
225 stack.push(index);
@@ -521,6 +521,26 @@ impl Tree {
521 Some(child_id)
521 Some(child_id)
524+ pub fn prev(&self) -> ViewId {
525+ // This function is very dumb, but that's because we don't store any parent links.
526+ // (we'd be able to go parent.prev_sibling() recursively until we find something)
527+ // For now that's okay though, since it's unlikely you'll be able to open a large enough
528+ // number of splits to notice.
530+ let mut views = self
533+ .skip_while(|&(id, _view)| id != self.focus)
534+ .skip(1); // Skip focused value
535+ if let Some((id, _)) = views.next() {
538+ // extremely crude, take the last item
539+ let (key, _) = self.traverse().rev().next().unwrap();
524 pub fn next(&self) -> ViewId {
544 pub fn next(&self) -> ViewId {
525 // This function is very dumb, but that's because we don't store any parent links.
545 // This function is very dumb, but that's because we don't store any parent links.
526 // (we'd be able to go parent.next_sibling() recursively until we find something)
546 // (we'd be able to go parent.next_sibling() recursively until we find something)
@@ -661,6 +681,23 @@ impl<'a> Iterator for Traverse<'a> {
684+impl<'a> DoubleEndedIterator for Traverse<'a> {
685+ fn next_back(&mut self) -> Option<Self::Item> {
687+ let key = self.stack.pop()?;
689+ let node = &self.tree.nodes[key];
691+ match &node.content {
692+ Content::View(view) => return Some((key, view)),
693+ Content::Container(container) => {
694+ self.stack.extend(container.children.iter());
664#[cfg(test)]
701#[cfg(test)]
665mod test {
702mod test {
666 use super::*;
703 use super::*;