File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -92,14 +92,26 @@ function check_gallery(id_gallery){
92
92
if ( prevSelectedIndex !== - 1 && galleryButtons . length > prevSelectedIndex && ! galleryBtnSelected ) {
93
93
// automatically re-open previously selected index (if exists)
94
94
activeElement = gradioApp ( ) . activeElement ;
95
+ let scrollX = window . scrollX ;
96
+ let scrollY = window . scrollY ;
95
97
96
98
galleryButtons [ prevSelectedIndex ] . click ( ) ;
97
99
showGalleryImage ( ) ;
98
100
101
+ // When the gallery button is clicked, it gains focus and scrolls itself into view
102
+ // We need to scroll back to the previous position
103
+ setTimeout ( function ( ) {
104
+ window . scrollTo ( scrollX , scrollY ) ;
105
+ } , 50 ) ;
106
+
99
107
if ( activeElement ) {
100
108
// i fought this for about an hour; i don't know why the focus is lost or why this helps recover it
101
- // if somenoe has a better solution please by all means
102
- setTimeout ( function ( ) { activeElement . focus ( ) } , 1 ) ;
109
+ // if someone has a better solution please by all means
110
+ setTimeout ( function ( ) {
111
+ activeElement . focus ( {
112
+ preventScroll : true // Refocus the element that was focused before the gallery was opened without scrolling to it
113
+ } )
114
+ } , 1 ) ;
103
115
}
104
116
}
105
117
} )
You can’t perform that action at this time.
0 commit comments