1
1
use std:: { collections:: BTreeMap , mem:: take, ops:: Bound } ;
2
2
3
3
use egui:: {
4
- text:: LayoutJob , CollapsingHeader , Color32 , Id , OpenUrl , ScrollArea , SelectableLabel , TextEdit ,
5
- Ui , Widget ,
4
+ style :: ScrollAnimation , text:: LayoutJob , CollapsingHeader , Color32 , Id , OpenUrl , ScrollArea ,
5
+ SelectableLabel , TextEdit , Ui , Widget ,
6
6
} ;
7
7
use objdiff_core:: {
8
8
arch:: ObjArch ,
@@ -57,8 +57,8 @@ pub enum DiffViewAction {
57
57
Build ,
58
58
/// Navigate to a new diff view
59
59
Navigate ( DiffViewNavigation ) ,
60
- /// Set the highlighted symbols in the symbols view
61
- SetSymbolHighlight ( Option < SymbolRef > , Option < SymbolRef > ) ,
60
+ /// Set the highlighted symbols in the symbols view, optionally scrolling them into view.
61
+ SetSymbolHighlight ( Option < SymbolRef > , Option < SymbolRef > , bool ) ,
62
62
/// Set the symbols view search filter
63
63
SetSearch ( String ) ,
64
64
/// Submit the current function to decomp.me
@@ -136,6 +136,7 @@ pub struct DiffViewState {
136
136
#[ derive( Default ) ]
137
137
pub struct SymbolViewState {
138
138
pub highlighted_symbol : ( Option < SymbolRef > , Option < SymbolRef > ) ,
139
+ pub scroll_highlighted_symbol_into_view : bool ,
139
140
pub left_symbol : Option < SymbolRefByName > ,
140
141
pub right_symbol : Option < SymbolRefByName > ,
141
142
pub reverse_fn_order : bool ,
@@ -247,8 +248,9 @@ impl DiffViewState {
247
248
self . post_build_nav = Some ( nav) ;
248
249
}
249
250
}
250
- DiffViewAction :: SetSymbolHighlight ( left, right) => {
251
+ DiffViewAction :: SetSymbolHighlight ( left, right, scroll ) => {
251
252
self . symbol_state . highlighted_symbol = ( left, right) ;
253
+ self . symbol_state . scroll_highlighted_symbol_into_view = scroll;
252
254
}
253
255
DiffViewAction :: SetSearch ( search) => {
254
256
self . search_regex = if search. is_empty ( ) {
@@ -471,7 +473,7 @@ fn symbol_ui(
471
473
symbol : & ObjSymbol ,
472
474
symbol_diff : & ObjSymbolDiff ,
473
475
section : Option < & ObjSection > ,
474
- state : & SymbolViewState ,
476
+ state : & mut SymbolViewState ,
475
477
appearance : & Appearance ,
476
478
column : usize ,
477
479
) -> Option < DiffViewAction > {
@@ -534,6 +536,14 @@ fn symbol_ui(
534
536
ret = Some ( DiffViewAction :: Navigate ( result) ) ;
535
537
}
536
538
} ) ;
539
+ if selected && state. scroll_highlighted_symbol_into_view {
540
+ // Scroll the view to encompass the selected symbol in case the user selected an offscreen
541
+ // symbol by using a keyboard shortcut.
542
+ ui. scroll_to_rect_animation ( response. rect , None , ScrollAnimation :: none ( ) ) ;
543
+ // Then reset this flag so that we don't repeatedly scroll the view back when the user is
544
+ // trying to manually scroll away.
545
+ state. scroll_highlighted_symbol_into_view = false ;
546
+ }
537
547
if response. clicked ( ) || ( selected && hotkeys:: enter_pressed ( ui. ctx ( ) ) ) {
538
548
if let Some ( section) = section {
539
549
match section. kind {
@@ -565,11 +575,13 @@ fn symbol_ui(
565
575
DiffViewAction :: SetSymbolHighlight (
566
576
Some ( symbol_diff. symbol_ref ) ,
567
577
symbol_diff. target_symbol ,
578
+ false ,
568
579
)
569
580
} else {
570
581
DiffViewAction :: SetSymbolHighlight (
571
582
symbol_diff. target_symbol ,
572
583
Some ( symbol_diff. symbol_ref ) ,
584
+ false ,
573
585
)
574
586
} ) ;
575
587
}
@@ -603,7 +615,7 @@ pub fn symbol_list_ui(
603
615
ui : & mut Ui ,
604
616
ctx : SymbolDiffContext < ' _ > ,
605
617
other_ctx : Option < SymbolDiffContext < ' _ > > ,
606
- state : & SymbolViewState ,
618
+ state : & mut SymbolViewState ,
607
619
filter : SymbolFilter < ' _ > ,
608
620
appearance : & Appearance ,
609
621
column : usize ,
@@ -685,11 +697,13 @@ pub fn symbol_list_ui(
685
697
DiffViewAction :: SetSymbolHighlight (
686
698
Some ( * new_sym_ref) ,
687
699
new_symbol_diff. target_symbol ,
700
+ true ,
688
701
)
689
702
} else {
690
703
DiffViewAction :: SetSymbolHighlight (
691
704
new_symbol_diff. target_symbol ,
692
705
Some ( * new_sym_ref) ,
706
+ true ,
693
707
)
694
708
} ) ;
695
709
}
@@ -941,7 +955,7 @@ pub fn symbol_diff_ui(
941
955
. second_obj
942
956
. as_ref ( )
943
957
. map ( |( obj, diff) | SymbolDiffContext { obj, diff } ) ,
944
- & state. symbol_state ,
958
+ & mut state. symbol_state ,
945
959
filter,
946
960
appearance,
947
961
column,
@@ -965,7 +979,7 @@ pub fn symbol_diff_ui(
965
979
. first_obj
966
980
. as_ref ( )
967
981
. map ( |( obj, diff) | SymbolDiffContext { obj, diff } ) ,
968
- & state. symbol_state ,
982
+ & mut state. symbol_state ,
969
983
filter,
970
984
appearance,
971
985
column,
0 commit comments