@@ -219,7 +219,7 @@ impl Tree {
219
219
220
220
if self . focus == index {
221
221
// focus on something else
222
- self . focus = self . next ( ) ;
222
+ self . focus = self . prev ( ) ;
223
223
}
224
224
225
225
stack. push ( index) ;
@@ -521,6 +521,26 @@ impl Tree {
521
521
Some ( child_id)
522
522
}
523
523
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.next_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.
529
+
530
+ let mut views = self
531
+ . traverse ( )
532
+ . rev ( )
533
+ . skip_while ( |& ( id, _view) | id != self . focus )
534
+ . skip ( 1 ) ; // Skip focused value
535
+ if let Some ( ( id, _) ) = views. next ( ) {
536
+ id
537
+ } else {
538
+ // extremely crude, take the first item again
539
+ let ( key, _) = self . traverse ( ) . rev ( ) . next ( ) . unwrap ( ) ;
540
+ key
541
+ }
542
+ }
543
+
524
544
pub fn next ( & self ) -> ViewId {
525
545
// This function is very dumb, but that's because we don't store any parent links.
526
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> {
661
681
}
662
682
}
663
683
684
+ impl < ' a > DoubleEndedIterator for Traverse < ' a > {
685
+ fn next_back ( & mut self ) -> Option < Self :: Item > {
686
+ loop {
687
+ let key = self . stack . pop ( ) ?;
688
+
689
+ let node = & self . tree . nodes [ key] ;
690
+
691
+ match & node. content {
692
+ Content :: View ( view) => return Some ( ( key, view) ) ,
693
+ Content :: Container ( container) => {
694
+ self . stack . extend ( container. children . iter ( ) ) ;
695
+ }
696
+ }
697
+ }
698
+ }
699
+ }
700
+
664
701
#[ cfg( test) ]
665
702
mod test {
666
703
use super :: * ;
0 commit comments