aboutsummaryrefslogtreecommitdiff
path: root/javascript/progressbar.js
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2022-12-03 10:23:24 +0300
committerGitHub <noreply@github.com>2022-12-03 10:23:24 +0300
commit37fc1fa401c13369f42a77542d07ed81d6c8b59a (patch)
treefef342b445578ae24a88ddc354857d5085bda05e /javascript/progressbar.js
parentd2e5b4edfa90781430746dcf0cab4ce7dda4b3b3 (diff)
parentc4067c562698740d12ba01260627445f70f5bc24 (diff)
Merge pull request #5229 from lolsuffocate/master
Slightly improve page scroll jumping with focus
Diffstat (limited to 'javascript/progressbar.js')
-rw-r--r--javascript/progressbar.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/javascript/progressbar.js b/javascript/progressbar.js
index 43d1d1ce..d58737c4 100644
--- a/javascript/progressbar.js
+++ b/javascript/progressbar.js
@@ -92,14 +92,26 @@ function check_gallery(id_gallery){
if (prevSelectedIndex !== -1 && galleryButtons.length>prevSelectedIndex && !galleryBtnSelected) {
// automatically re-open previously selected index (if exists)
activeElement = gradioApp().activeElement;
+ let scrollX = window.scrollX;
+ let scrollY = window.scrollY;
galleryButtons[prevSelectedIndex].click();
showGalleryImage();
+ // When the gallery button is clicked, it gains focus and scrolls itself into view
+ // We need to scroll back to the previous position
+ setTimeout(function (){
+ window.scrollTo(scrollX, scrollY);
+ }, 50);
+
if(activeElement){
// i fought this for about an hour; i don't know why the focus is lost or why this helps recover it
- // if somenoe has a better solution please by all means
- setTimeout(function() { activeElement.focus() }, 1);
+ // if someone has a better solution please by all means
+ setTimeout(function (){
+ activeElement.focus({
+ preventScroll: true // Refocus the element that was focused before the gallery was opened without scrolling to it
+ })
+ }, 1);
}
}
})