diff --git a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.html b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.html index b0ef55d..2134b73 100644 --- a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.html +++ b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.html @@ -24,7 +24,7 @@
-
diff --git a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.ts b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.ts index ee8d354..f80356e 100644 --- a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.ts +++ b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.ts @@ -50,8 +50,19 @@ export class FileGalleryComponent implements OnChanges, OnInit { this.selectedFile?.unselect(); entry.select(); this.selectedFile = entry; + const selectedIndex = this.entries.indexOf(entry); + //this.virtualScroll.scrollToIndex(, "smooth"); await this.loadSelectedFile(); - this.virtualScroll.scrollToIndex(this.entries.indexOf(entry), "smooth"); + + if (this.virtualScroll) { + const viewportSize = this.virtualScroll.getViewportSize(); + const indexAdjustment = (viewportSize / 260) / 2; // adjustment to have the selected item centered + this.virtualScroll.scrollToIndex(Math.max(selectedIndex - indexAdjustment, 0), "smooth"); + + if (selectedIndex > indexAdjustment) { + this.virtualScroll.scrollToOffset(this.virtualScroll.measureScrollOffset("left") + 130, "smooth"); + } + } this.fileSelectEvent.emit(this.selectedFile.data); } }