diff --git a/javascript/ui.js b/javascript/ui.js index ff6f8974b0e..dba4d97beb6 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -26,6 +26,11 @@ function selected_gallery_index() { return all_gallery_buttons().findIndex(elem => elem.classList.contains('selected')); } +function selected_gallery_index_gallery_container(gallery_container) { + var tabGalleryButtons = gradioApp().querySelectorAll(`#${gallery_container} .thumbnail-item.thumbnail-small`); + return Array.from(tabGalleryButtons).findIndex(elem => elem.classList.contains('selected')); +} + function extract_image_from_gallery(gallery) { if (gallery.length == 0) { return [null]; diff --git a/modules/ui_extra_networks_user_metadata.py b/modules/ui_extra_networks_user_metadata.py index fde093700b8..066d9955edb 100644 --- a/modules/ui_extra_networks_user_metadata.py +++ b/modules/ui_extra_networks_user_metadata.py @@ -194,7 +194,7 @@ def save_preview(self, index, gallery, name): def setup_ui(self, gallery): self.button_replace_preview.click( fn=self.save_preview, - _js="function(x, y, z){return [selected_gallery_index(), y, z]}", + _js=f"function(x, y, z){{return [selected_gallery_index_gallery_container('{self.tabname + '_gallery_container'}'), y, z]}}", inputs=[self.edit_name_input, gallery, self.edit_name_input], outputs=[self.html_preview, self.html_status] ).then(