1
- use crate :: { graphics:: Rect , View , ViewId } ;
1
+ use crate :: { graphics:: Rect , DocumentId , View , ViewId } ;
2
2
use slotmap:: HopSlotMap ;
3
3
4
4
// the dimensions are recomputed on window resize/tree change.
@@ -29,6 +29,12 @@ pub enum Content {
29
29
Container ( Box < Container > ) ,
30
30
}
31
31
32
+ #[ derive( Debug ) ]
33
+ pub struct ViewSwap {
34
+ pub documents : [ DocumentId ; 2 ] ,
35
+ pub views : [ ViewId ; 2 ] ,
36
+ }
37
+
32
38
impl Node {
33
39
pub fn container ( layout : Layout ) -> Self {
34
40
Self {
@@ -526,14 +532,18 @@ impl Tree {
526
532
}
527
533
}
528
534
529
- pub fn swap_split_in_direction ( & mut self , direction : Direction ) {
535
+ pub fn swap_split_in_direction ( & mut self , direction : Direction ) -> Option < ViewSwap > {
530
536
if let Some ( id) = self . find_split_in_direction ( self . focus , direction) {
531
537
if let Some ( [ focused, target] ) = self . nodes . get_disjoint_mut ( [ self . focus , id] ) {
532
538
match ( & mut focused. content , & mut target. content ) {
533
539
( Content :: View ( focused) , Content :: View ( target) ) => {
534
- std:: mem:: swap ( & mut focused. doc , & mut target. doc ) ;
535
- std:: mem:: swap ( & mut focused. id , & mut target. id ) ;
540
+ View :: swap_content ( focused, target) ;
536
541
self . focus = id;
542
+
543
+ return Some ( ViewSwap {
544
+ documents : [ focused. doc , target. doc ] ,
545
+ views : [ focused. id , target. id ] ,
546
+ } ) ;
537
547
}
538
548
// self.focus always points to a view which has a content of Content::View
539
549
// and find_split_in_direction() only returns a view which has content of
@@ -542,6 +552,7 @@ impl Tree {
542
552
}
543
553
}
544
554
}
555
+ None
545
556
}
546
557
547
558
pub fn area ( & self ) -> Rect {
0 commit comments