@@ -374,18 +374,41 @@ local function update_playlist_menu(menu)
374374 local playlist = get (' playlist' , {})
375375 if # playlist == 0 then return end
376376
377- for id , item in ipairs (playlist ) do
378- if o .max_playlist_items > 0 and id > o .max_playlist_items then break end
377+ local pos = get (' playlist-playing-pos' , - 1 )
378+ if pos == - 1 then pos = get (' playlist-pos' , - 1 ) end
379+ local from , to = 1 , # playlist
380+ if o .max_playlist_items > 0 then
381+ if pos + 1 > o .max_playlist_items then
382+ local mid = math.floor (o .max_playlist_items / 2 )
383+ from , to = pos + 1 - mid , pos + (o .max_playlist_items - mid )
384+ if from < 1 then from , to = 1 , o .max_playlist_items end
385+ if to > # playlist then from , to = # playlist - o .max_playlist_items + 1 , # playlist end
386+ else
387+ from , to = 1 , o .max_playlist_items
388+ end
389+ end
390+
391+ if from > 1 then
379392 submenu [# submenu + 1 ] = {
380- title = build_playlist_title (item , id - 1 ),
381- cmd = string.format (' playlist-play-index %d' , id - 1 ),
382- state = item .current and { ' checked' } or {},
393+ title = string.format (' ...\t [%d]' , from - 1 ),
394+ cmd = has_uosc and ' script-message-to uosc playlist' or ' ignore' ,
383395 }
384396 end
385397
386- if o .max_playlist_items > 0 and # playlist > o .max_playlist_items then
398+ for id = from , to do
399+ local item = playlist [id ]
400+ if item then
401+ submenu [# submenu + 1 ] = {
402+ title = build_playlist_title (item , id - 1 ),
403+ cmd = string.format (' playlist-play-index %d' , id - 1 ),
404+ state = (item .playing or item .current ) and { ' checked' } or {},
405+ }
406+ end
407+ end
408+
409+ if to < # playlist then
387410 submenu [# submenu + 1 ] = {
388- title = string.format (' ...\t [%d]' , # playlist - o . max_playlist_items ),
411+ title = string.format (' ...\t [%d]' , # playlist - to ),
389412 cmd = has_uosc and ' script-message-to uosc playlist' or ' ignore' ,
390413 }
391414 end
0 commit comments