fix: don't stop playback when deleting the current track from playlist

This commit is contained in:
Armin 2026-07-08 16:34:07 +02:00
commit 154f003787

View file

@ -1045,7 +1045,18 @@ function deleteTrack() {
if (selectedIndices.size === 0) return; if (selectedIndices.size === 0) return;
const sortedSel = [...selectedIndices].sort((a, b) => a - b); const sortedSel = [...selectedIndices].sort((a, b) => a - b);
const willDeleteCurrent = selectedIndices.has(currentIndex); 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.pause();
audio.currentTime = 0; audio.currentTime = 0;
if (isCrossfading) { if (isCrossfading) {
@ -1069,6 +1080,10 @@ function deleteTrack() {
for (let j = sortedSel.length - 1; j >= 0; j--) tracks.splice(sortedSel[j], 1); for (let j = sortedSel.length - 1; j >= 0; j--) tracks.splice(sortedSel[j], 1);
selectedIndices.clear(); selectedIndices.clear();
if (willDeleteCurrent) { if (willDeleteCurrent) {
if (playNextOrigIdx >= 0) {
const removedBefore = sortedSel.filter(idx => idx < playNextOrigIdx).length;
pendingNextIndex = playNextOrigIdx - removedBefore;
}
currentIndex = -1; currentIndex = -1;
} else { } else {
const removedBefore = sortedSel.filter(idx => idx < currentIndex).length; const removedBefore = sortedSel.filter(idx => idx < currentIndex).length;