@@ -17,6 +17,7 @@ import {
17
17
RTCConnection ,
18
18
TlsTunnel
19
19
} from '../../types' ;
20
+ import { UiStore } from '../../model/ui/ui-store' ;
20
21
21
22
import {
22
23
getSummaryColor ,
@@ -54,6 +55,7 @@ interface ViewEventListProps {
54
55
isPaused : boolean ;
55
56
56
57
contextMenuBuilder : ViewEventContextMenuBuilder ;
58
+ uiStore : UiStore ;
57
59
58
60
moveSelection : ( distance : number ) => void ;
59
61
onSelected : ( event : CollectedEvent | undefined ) => void ;
@@ -879,19 +881,37 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
879
881
if ( ! listWindow ) return true ; // This means no rows, so we are effectively at the bottom
880
882
else return ( listWindow . scrollTop + SCROLL_BOTTOM_MARGIN ) >= ( listWindow . scrollHeight - listWindow . offsetHeight ) ;
881
883
}
882
-
883
884
private wasListAtBottom = true ;
884
885
private updateScrolledState = ( ) => {
885
886
requestAnimationFrame ( ( ) => { // Measure async, once the scroll has actually happened
886
887
this . wasListAtBottom = this . isListAtBottom ( ) ;
888
+
889
+ // Only save scroll position after we've restored the initial state
890
+ if ( this . hasRestoredInitialState ) {
891
+ const listWindow = this . listBodyRef . current ?. parentElement ;
892
+ if ( listWindow ) {
893
+ this . props . uiStore . setViewScrollPosition ( listWindow . scrollTop ) ;
894
+ }
895
+ }
887
896
} ) ;
888
897
}
889
898
899
+ private hasRestoredInitialState = false ;
890
900
componentDidMount ( ) {
891
- this . updateScrolledState ( ) ;
901
+ // Don't save scroll state immediately - wait until we've restored first
902
+
903
+ // Use a more aggressive delay to ensure DOM is fully ready
904
+ setTimeout ( ( ) => {
905
+ this . restoreScrollPosition ( ) ;
906
+
907
+ // Only start tracking scroll changes after we've restored
908
+ setTimeout ( ( ) => {
909
+ this . hasRestoredInitialState = true ;
910
+ } , 100 ) ;
911
+ } , 100 ) ;
892
912
}
893
913
894
- componentDidUpdate ( ) {
914
+ componentDidUpdate ( prevProps : ViewEventListProps ) {
895
915
if ( this . listBodyRef . current ?. parentElement ?. contains ( document . activeElement ) ) {
896
916
// If we previously had something here focused, and we've updated, update
897
917
// the focus too, to make sure it's in the right place.
@@ -901,7 +921,29 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
901
921
// If we previously were scrolled to the bottom of the list, but now we're not,
902
922
// scroll there again ourselves now.
903
923
if ( this . wasListAtBottom && ! this . isListAtBottom ( ) ) {
904
- this . listRef . current ?. scrollToItem ( this . props . events . length - 1 ) ;
924
+ this . listRef . current ?. scrollToItem ( this . props . events . length - 1 ) ;
925
+ } else if ( prevProps . selectedEvent !== this . props . selectedEvent && this . props . selectedEvent ) {
926
+ // If the selected event changed and we have a selected event, scroll to it
927
+ // This handles restoring the selected event when returning to the tab
928
+ this . scrollToEvent ( this . props . selectedEvent ) ;
929
+ } else if ( prevProps . filteredEvents . length !== this . props . filteredEvents . length ) {
930
+ // If the filtered events changed (e.g., new events loaded), try to restore scroll position
931
+ setTimeout ( ( ) => {
932
+ this . restoreScrollPosition ( ) ;
933
+ } , 50 ) ;
934
+ }
935
+ }
936
+
937
+ private restoreScrollPosition = ( ) => {
938
+ // Only restore if we have a saved position
939
+ const savedPosition = this . props . uiStore . viewScrollPosition ;
940
+ if ( savedPosition > 0 ) {
941
+ const listWindow = this . listBodyRef . current ?. parentElement ;
942
+ if ( listWindow ) { // Only restore if we're not close to the current position (avoid unnecessary scrolling)
943
+ if ( Math . abs ( listWindow . scrollTop - savedPosition ) > 10 ) {
944
+ listWindow . scrollTop = savedPosition ;
945
+ }
946
+ }
905
947
}
906
948
}
907
949
@@ -1005,5 +1047,12 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
1005
1047
}
1006
1048
1007
1049
event . preventDefault ( ) ;
1050
+ } // Public method to force scroll and selection restoration
1051
+ public restoreViewState = ( ) => {
1052
+ if ( this . props . selectedEvent ) {
1053
+ this . scrollToEvent ( this . props . selectedEvent ) ;
1054
+ } else {
1055
+ this . restoreScrollPosition ( ) ;
1056
+ }
1008
1057
}
1009
1058
}
0 commit comments