From 154f00378719d597f039499ca4ed912b611c7aaf Mon Sep 17 00:00:00 2001 From: Armin Date: Wed, 8 Jul 2026 16:34:07 +0200 Subject: [PATCH] fix: don't stop playback when deleting the current track from playlist --- index.html | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index cd3edb2..6a10c87 100644 --- a/index.html +++ b/index.html @@ -1045,7 +1045,18 @@ function deleteTrack() { if (selectedIndices.size === 0) return; const sortedSel = [...selectedIndices].sort((a, b) => a - b); const willDeleteCurrent = selectedIndices.has(currentIndex); - if (willDeleteCurrent) { + let playNextOrigIdx = -1; + if (willDeleteCurrent && selectedIndices.size < tracks.length) { + for (let i = currentIndex + 1; i < tracks.length; i++) { + if (!selectedIndices.has(i)) { playNextOrigIdx = i; break; } + } + if (playNextOrigIdx === -1) { + for (let i = currentIndex - 1; i >= 0; i--) { + if (!selectedIndices.has(i)) { playNextOrigIdx = i; break; } + } + } + } + if (willDeleteCurrent && playNextOrigIdx === -1) { audio.pause(); audio.currentTime = 0; if (isCrossfading) { @@ -1069,6 +1080,10 @@ function deleteTrack() { for (let j = sortedSel.length - 1; j >= 0; j--) tracks.splice(sortedSel[j], 1); selectedIndices.clear(); if (willDeleteCurrent) { + if (playNextOrigIdx >= 0) { + const removedBefore = sortedSel.filter(idx => idx < playNextOrigIdx).length; + pendingNextIndex = playNextOrigIdx - removedBefore; + } currentIndex = -1; } else { const removedBefore = sortedSel.filter(idx => idx < currentIndex).length;