1- import { defineComponent } from "vue" ;
1+ import { defineComponent , ref , watch , nextTick } from "vue" ;
22import { MusicXmlWithABJacket } from "@/client/apiGen" ;
33import { Button , theme } from "@munet/ui" ;
44import { VList } from 'virtua/vue' ;
55import MusicEntry from "@/views/Charts/MusicList/MusicEntry" ;
66import { assetDirs , musicList , selectedADir , selectMusicId } from "@/store/refs" ;
77import { leftPanel } from "@/views/Charts/refs" ;
88
9+ export const musicListRef = ref < InstanceType < typeof VList > | null > ( null ) ;
10+
11+ export const scrollToMusic = ( musicId : number ) => {
12+ const idx = musicList . value . findIndex ( m => m . id === musicId ) ;
13+ if ( idx === - 1 || ! musicListRef . value ) return ;
14+ musicListRef . value . scrollToIndex ( idx , { align : 'center' , smooth : true } ) ;
15+ } ;
16+
917export default defineComponent ( {
1018 props : {
1119 toggleMenu : { type : Function , required : true } ,
@@ -30,7 +38,7 @@ export default defineComponent({
3038 < span class = "truncate" > { selectedDirLabel ( ) } </ span >
3139 </ div >
3240 </ div >
33- < VList class = "flex-1 cst" data = { musicList . value } >
41+ < VList ref = { musicListRef } class = "flex-1 cst" data = { musicList . value } >
3442 { ( { item} : { item : MusicXmlWithABJacket } ) => (
3543 < MusicEntry music = { item } selected = { selectMusicId . value === item . id } onClick = { ( ) => selectMusicId . value = item . id ! } key = { item . id } />
3644 ) }
0 commit comments