@@ -88,12 +88,16 @@ impl FloatingPanes {
88
88
}
89
89
pub fn stack ( & self ) -> Option < FloatingPanesStack > {
90
90
if self . panes_are_visible ( ) {
91
- let layers = self
91
+ let layers: Vec < PaneGeom > = self
92
92
. z_indices
93
93
. iter ( )
94
- . map ( |pane_id| self . panes . get ( pane_id) . unwrap ( ) . position_and_size ( ) )
94
+ . filter_map ( |pane_id| self . panes . get ( pane_id) . map ( |p| p . position_and_size ( ) ) )
95
95
. collect ( ) ;
96
- Some ( FloatingPanesStack { layers } )
96
+ if layers. is_empty ( ) {
97
+ None
98
+ } else {
99
+ Some ( FloatingPanesStack { layers } )
100
+ }
97
101
} else if self . has_pinned_panes ( ) {
98
102
let layers = self
99
103
. z_indices
@@ -257,7 +261,8 @@ impl FloatingPanes {
257
261
pub fn position_floating_pane_layout (
258
262
& mut self ,
259
263
floating_pane_layout : & FloatingPaneLayout ,
260
- ) -> PaneGeom {
264
+ ) -> Result < PaneGeom > {
265
+ let err_context = || format ! ( "failed to find position for floating pane" ) ;
261
266
let display_area = * self . display_area . borrow ( ) ;
262
267
let viewport = * self . viewport . borrow ( ) ;
263
268
let floating_pane_grid = FloatingPaneGrid :: new (
@@ -266,7 +271,9 @@ impl FloatingPanes {
266
271
display_area,
267
272
viewport,
268
273
) ;
269
- let mut position = floating_pane_grid. find_room_for_new_pane ( ) . unwrap ( ) ; // TODO: no unwrap
274
+ let mut position = floating_pane_grid
275
+ . find_room_for_new_pane ( )
276
+ . with_context ( err_context) ?;
270
277
if let Some ( x) = & floating_pane_layout. x {
271
278
position. x = x. to_position ( viewport. cols ) ;
272
279
}
@@ -301,7 +308,7 @@ impl FloatingPanes {
301
308
. y
302
309
. saturating_sub ( ( position. y + position. rows . as_usize ( ) ) - viewport. rows ) ;
303
310
}
304
- position
311
+ Ok ( position)
305
312
}
306
313
pub fn first_floating_pane_id ( & self ) -> Option < PaneId > {
307
314
self . panes . keys ( ) . next ( ) . copied ( )
@@ -432,7 +439,7 @@ impl FloatingPanes {
432
439
display_area,
433
440
viewport,
434
441
) ;
435
- floating_pane_grid. resize ( new_screen_size) . unwrap ( ) ;
442
+ floating_pane_grid. resize ( new_screen_size) . non_fatal ( ) ;
436
443
self . set_force_render ( ) ;
437
444
}
438
445
@@ -530,17 +537,20 @@ impl FloatingPanes {
530
537
Some ( p) => {
531
538
// render previously active pane so that its frame does not remain actively
532
539
// colored
533
- let previously_active_pane = self
534
- . panes
535
- . get_mut ( self . active_panes . get ( & client_id ) . unwrap ( ) )
536
- . unwrap ( ) ;
540
+ let Some ( previously_active_pane) = self . get_active_pane_mut ( client_id ) else {
541
+ log :: error! ( "Failed to get active pane" ) ;
542
+ return Ok ( false ) ;
543
+ } ;
537
544
538
545
previously_active_pane. set_should_render ( true ) ;
539
546
// we render the full viewport to remove any ui elements that might have been
540
547
// there before (eg. another user's cursor)
541
548
previously_active_pane. render_full_viewport ( ) ;
542
549
543
- let next_active_pane = self . panes . get_mut ( & p) . unwrap ( ) ;
550
+ let Some ( next_active_pane) = self . get_pane_mut ( p) else {
551
+ log:: error!( "Failed to get next active pane" ) ;
552
+ return Ok ( false ) ;
553
+ } ;
544
554
next_active_pane. set_should_render ( true ) ;
545
555
// we render the full viewport to remove any ui elements that might have been
546
556
// there before (eg. another user's cursor)
@@ -588,9 +598,10 @@ impl FloatingPanes {
588
598
display_area,
589
599
viewport,
590
600
) ;
591
- let pane_id = floating_pane_grid. pane_id_on_edge ( direction) . unwrap ( ) ;
592
- self . focus_pane ( pane_id, client_id) ;
593
- self . set_force_render ( ) ;
601
+ if let Some ( pane_id) = floating_pane_grid. pane_id_on_edge ( direction) {
602
+ self . focus_pane ( pane_id, client_id) ;
603
+ self . set_force_render ( ) ;
604
+ }
594
605
}
595
606
596
607
pub fn move_active_pane_down ( & mut self , client_id : ClientId ) {
@@ -641,7 +652,7 @@ impl FloatingPanes {
641
652
display_area,
642
653
viewport,
643
654
) ;
644
- floating_pane_grid. move_pane_left ( & pane_id) . unwrap ( ) ;
655
+ floating_pane_grid. move_pane_left ( & pane_id) . non_fatal ( ) ;
645
656
self . set_force_render ( ) ;
646
657
}
647
658
pub fn move_active_pane_right ( & mut self , client_id : ClientId ) {
@@ -658,7 +669,7 @@ impl FloatingPanes {
658
669
display_area,
659
670
viewport,
660
671
) ;
661
- floating_pane_grid. move_pane_right ( & pane_id) . unwrap ( ) ;
672
+ floating_pane_grid. move_pane_right ( & pane_id) . non_fatal ( ) ;
662
673
self . set_force_render ( ) ;
663
674
}
664
675
pub fn move_active_pane (
@@ -667,8 +678,9 @@ impl FloatingPanes {
667
678
_os_api : & mut Box < dyn ServerOsApi > ,
668
679
client_id : ClientId ,
669
680
) {
670
- let active_pane_id = self . get_active_pane_id ( client_id) . unwrap ( ) ;
671
- self . move_pane ( search_backwards, active_pane_id)
681
+ if let Some ( active_pane_id) = self . get_active_pane_id ( client_id) {
682
+ self . move_pane ( search_backwards, active_pane_id)
683
+ }
672
684
}
673
685
pub fn move_pane ( & mut self , search_backwards : bool , pane_id : PaneId ) {
674
686
let new_position_id = {
@@ -685,11 +697,17 @@ impl FloatingPanes {
685
697
}
686
698
} ;
687
699
if let Some ( new_position_id) = new_position_id {
688
- let current_position = self . panes . get ( & pane_id) . unwrap ( ) ;
700
+ let Some ( current_position) = self . panes . get ( & pane_id) else {
701
+ log:: error!( "Failed to find current position" ) ;
702
+ return ;
703
+ } ;
689
704
let prev_geom = current_position. position_and_size ( ) ;
690
705
let prev_geom_override = current_position. geom_override ( ) ;
691
706
692
- let new_position = self . panes . get_mut ( & new_position_id) . unwrap ( ) ;
707
+ let Some ( new_position) = self . panes . get_mut ( & new_position_id) else {
708
+ log:: error!( "Failed to find new position" ) ;
709
+ return ;
710
+ } ;
693
711
let next_geom = new_position. position_and_size ( ) ;
694
712
let next_geom_override = new_position. geom_override ( ) ;
695
713
new_position. set_geom ( prev_geom) ;
@@ -698,7 +716,10 @@ impl FloatingPanes {
698
716
}
699
717
new_position. set_should_render ( true ) ;
700
718
701
- let current_position = self . panes . get_mut ( & pane_id) . unwrap ( ) ;
719
+ let Some ( current_position) = self . panes . get_mut ( & pane_id) else {
720
+ log:: error!( "Failed to find current position" ) ;
721
+ return ;
722
+ } ;
702
723
current_position. set_geom ( next_geom) ;
703
724
if let Some ( geom) = next_geom_override {
704
725
current_position. set_geom_override ( geom) ;
@@ -801,8 +822,16 @@ impl FloatingPanes {
801
822
panes. sort_by ( |( a_id, _a_pane) , ( b_id, _b_pane) | {
802
823
// TODO: continue
803
824
Ord :: cmp (
804
- & self . z_indices . iter ( ) . position ( |id| id == * b_id) . unwrap ( ) ,
805
- & self . z_indices . iter ( ) . position ( |id| id == * a_id) . unwrap ( ) ,
825
+ & self
826
+ . z_indices
827
+ . iter ( )
828
+ . position ( |id| id == * b_id)
829
+ . unwrap_or ( 0 ) ,
830
+ & self
831
+ . z_indices
832
+ . iter ( )
833
+ . position ( |id| id == * a_id)
834
+ . unwrap_or ( 0 ) ,
806
835
)
807
836
} ) ;
808
837
Ok ( panes
@@ -832,8 +861,16 @@ impl FloatingPanes {
832
861
panes. sort_by ( |( a_id, _a_pane) , ( b_id, _b_pane) | {
833
862
// TODO: continue
834
863
Ord :: cmp (
835
- & self . z_indices . iter ( ) . position ( |id| id == * b_id) . unwrap ( ) ,
836
- & self . z_indices . iter ( ) . position ( |id| id == * a_id) . unwrap ( ) ,
864
+ & self
865
+ . z_indices
866
+ . iter ( )
867
+ . position ( |id| id == * b_id)
868
+ . unwrap_or ( 0 ) ,
869
+ & self
870
+ . z_indices
871
+ . iter ( )
872
+ . position ( |id| id == * a_id)
873
+ . unwrap_or ( 0 ) ,
837
874
)
838
875
} ) ;
839
876
Ok ( panes
@@ -850,8 +887,16 @@ impl FloatingPanes {
850
887
851
888
panes. sort_by ( |( a_id, _a_pane) , ( b_id, _b_pane) | {
852
889
Ord :: cmp (
853
- & self . z_indices . iter ( ) . position ( |id| id == * b_id) . unwrap ( ) ,
854
- & self . z_indices . iter ( ) . position ( |id| id == * a_id) . unwrap ( ) ,
890
+ & self
891
+ . z_indices
892
+ . iter ( )
893
+ . position ( |id| id == * b_id)
894
+ . unwrap_or ( 0 ) ,
895
+ & self
896
+ . z_indices
897
+ . iter ( )
898
+ . position ( |id| id == * a_id)
899
+ . unwrap_or ( 0 ) ,
855
900
)
856
901
} ) ;
857
902
panes. iter ( ) . find ( |( _, p) | p. contains ( point) ) . is_some ( )
@@ -862,7 +907,7 @@ impl FloatingPanes {
862
907
search_selectable : bool ,
863
908
) -> Option < & mut Box < dyn Pane > > {
864
909
self . get_pane_id_at ( position, search_selectable)
865
- . unwrap ( )
910
+ . ok ( ) ?
866
911
. and_then ( |pane_id| self . panes . get_mut ( & pane_id) )
867
912
}
868
913
pub fn set_pane_being_moved_with_mouse ( & mut self , pane_id : PaneId , position : Position ) {
@@ -875,7 +920,10 @@ impl FloatingPanes {
875
920
// true => changed position
876
921
let display_area = * self . display_area . borrow ( ) ;
877
922
let viewport = * self . viewport . borrow ( ) ;
878
- let ( pane_id, previous_position) = self . pane_being_moved_with_mouse . unwrap ( ) ;
923
+ let Some ( ( pane_id, previous_position) ) = self . pane_being_moved_with_mouse else {
924
+ log:: error!( "Pane is not being moved with mousd" ) ;
925
+ return false ;
926
+ } ;
879
927
if click_position == & previous_position {
880
928
return false ;
881
929
}
@@ -889,7 +937,7 @@ impl FloatingPanes {
889
937
) ;
890
938
floating_pane_grid
891
939
. move_pane_by ( pane_id, move_x_by, move_y_by)
892
- . unwrap ( ) ;
940
+ . non_fatal ( ) ;
893
941
self . set_pane_being_moved_with_mouse ( pane_id, * click_position) ;
894
942
self . set_force_render ( ) ;
895
943
true
@@ -962,21 +1010,30 @@ impl FloatingPanes {
962
1010
}
963
1011
pub fn switch_active_pane_with ( & mut self , _os_api : & mut Box < dyn ServerOsApi > , pane_id : PaneId ) {
964
1012
if let Some ( active_pane_id) = self . first_active_floating_pane_id ( ) {
965
- let current_position = self . panes . get ( & active_pane_id) . unwrap ( ) ;
1013
+ let Some ( current_position) = self . panes . get ( & active_pane_id) else {
1014
+ log:: error!( "Can't find current position" ) ;
1015
+ return ;
1016
+ } ;
966
1017
let prev_geom = current_position. position_and_size ( ) ;
967
1018
let prev_geom_override = current_position. geom_override ( ) ;
968
1019
969
- let new_position = self . panes . get_mut ( & pane_id) . unwrap ( ) ;
1020
+ let Some ( new_position) = self . panes . get_mut ( & pane_id) else {
1021
+ log:: error!( "Can't find position" ) ;
1022
+ return ;
1023
+ } ;
970
1024
let next_geom = new_position. position_and_size ( ) ;
971
1025
let next_geom_override = new_position. geom_override ( ) ;
972
1026
new_position. set_geom ( prev_geom) ;
973
1027
if let Some ( geom) = prev_geom_override {
974
1028
new_position. set_geom_override ( geom) ;
975
1029
}
976
- resize_pty ! ( new_position, os_api, self . senders, self . character_cell_size) . unwrap ( ) ;
1030
+ resize_pty ! ( new_position, os_api, self . senders, self . character_cell_size) . non_fatal ( ) ;
977
1031
new_position. set_should_render ( true ) ;
978
1032
979
- let current_position = self . panes . get_mut ( & active_pane_id) . unwrap ( ) ;
1033
+ let Some ( current_position) = self . panes . get_mut ( & active_pane_id) else {
1034
+ log:: error!( "Can't find current position" ) ;
1035
+ return ;
1036
+ } ;
980
1037
current_position. set_geom ( next_geom) ;
981
1038
if let Some ( geom) = next_geom_override {
982
1039
current_position. set_geom_override ( geom) ;
@@ -987,7 +1044,7 @@ impl FloatingPanes {
987
1044
self . senders,
988
1045
self . character_cell_size
989
1046
)
990
- . unwrap ( ) ;
1047
+ . non_fatal ( ) ;
991
1048
current_position. set_should_render ( true ) ;
992
1049
self . focus_pane_for_all_clients ( active_pane_id) ;
993
1050
}
0 commit comments