diff options
author | Florrie <towerofnix@gmail.com> | 2019-09-06 15:49:04 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2019-09-06 15:49:04 -0300 |
commit | 366b6e90f1d237a8e1e0d92224f65990157d0cd6 (patch) | |
tree | 021b43998820013cde5e21344c9640b98e62dd28 /backend.js | |
parent | d51c3b00e4b097dbae0707d1ef14dc41298ad0a1 (diff) |
Fix songs from before insert index queuing wrongly
Now /that/ was hard to fit in the commit line length. (:
Diffstat (limited to 'backend.js')
-rw-r--r-- | backend.js | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/backend.js b/backend.js index d88c779..0ddd15b 100644 --- a/backend.js +++ b/backend.js @@ -140,6 +140,10 @@ class Backend extends EventEmitter { // a whole group can be queued in order after a given item. let grouplikeOffset = 0 + // Keeps track of how many tracks have been removed (times -1); this is + // used so we queue tracks at the intended spot. + let removeOffset = 0 + const recursivelyAddTracks = item => { // For groups, just queue all children. if (isGroup(item)) { @@ -163,13 +167,22 @@ class Backend extends EventEmitter { if (!movePlayingTrack && item === this.playingTrack) { return } - items.splice(items.indexOf(item), 1) + + const removeIndex = items.indexOf(item) + items.splice(removeIndex, 1) + + // If the item we removed was positioned before the insertion index, + // we need to shift that index back one, so it's placed after the same + // intended track. + if (removeIndex <= afterIndex) { + removeOffset-- + } } if (afterItem === 'FRONT') { items.unshift(item) } else if (afterItem) { - items.splice(afterIndex + 1 + grouplikeOffset, 0, item) + items.splice(afterIndex + 1 + grouplikeOffset + removeOffset, 0, item) } else { items.push(item) } |