File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
src/renderer/components/WatchVideoPlaylist Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -692,21 +692,26 @@ function parseUserPlaylist(playlist) {
692692
693693function shufflePlaylistItems () {
694694 // Prevents the array from affecting the original object
695- const remainingItems = [].concat (playlistItems .value )
696- const items = []
695+ const items = playlistItems .value .slice ()
696+
697+ let cachedCurrentVideo
697698
698699 if (currentVideo .value != null ) {
699- items .push (currentVideo .value )
700- remainingItems .splice (currentVideoIndexZeroBased .value , 1 )
700+ cachedCurrentVideo = items .splice (currentVideoIndexZeroBased .value , 1 )
701701 // There is no else case
702702 // If current video is absent in (removed from) the playlist, nothing should be changed
703703 }
704704
705- while (remainingItems .length > 0 ) {
706- const randomInt = Math .floor (Math .random () * remainingItems .length )
705+ for (let i = items .length - 1 ; i > 0 ; i-- ) {
706+ const j = Math .floor (Math .random () * (i + 1 ))
707+
708+ const temp = items[i]
709+ items[i] = items[j]
710+ items[j] = temp
711+ }
707712
708- items . push (remainingItems[randomInt])
709- remainingItems . splice (randomInt, 1 )
713+ if (cachedCurrentVideo !== undefined ) {
714+ items . unshift (cachedCurrentVideo )
710715 }
711716
712717 randomizedPlaylistItems .value = items
You can’t perform that action at this time.
0 commit comments