From 3da3a5e482d7623c817343c821de662962314c74 Mon Sep 17 00:00:00 2001 From: peterino2 Date: Fri, 6 Feb 2026 09:00:23 -0800 Subject: [PATCH] updated queue editing and basic playlist functionality --- public/queue.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/public/queue.js b/public/queue.js index be8f9d2..d2724c5 100644 --- a/public/queue.js +++ b/public/queue.js @@ -10,7 +10,10 @@ // Last selected index for shift-select range let lastSelectedQueueIndex = null; - let lastSelectedLibraryIndex = null; + let lastSelectedLibraryIndex = null; // Index in filtered list, not original library + + // Current filtered library (for shift-select to work correctly with search) + let currentFilteredLibrary = []; // Context menu state let activeContextMenu = null; @@ -341,22 +344,26 @@ M.renderQueue(); }; - M.toggleLibrarySelection = function(index, shiftKey = false) { - if (shiftKey && lastSelectedLibraryIndex !== null) { - // Range select: select all between last and current - const start = Math.min(lastSelectedLibraryIndex, index); - const end = Math.max(lastSelectedLibraryIndex, index); + M.toggleLibrarySelection = function(filteredIndex, shiftKey = false) { + if (shiftKey && lastSelectedLibraryIndex !== null && currentFilteredLibrary.length > 0) { + // Range select: select all between last and current in FILTERED list + const start = Math.min(lastSelectedLibraryIndex, filteredIndex); + const end = Math.max(lastSelectedLibraryIndex, filteredIndex); for (let i = start; i <= end; i++) { - M.selectedLibraryIds.add(M.library[i].id); + if (currentFilteredLibrary[i]) { + M.selectedLibraryIds.add(currentFilteredLibrary[i].track.id); + } } } else { - const trackId = M.library[index].id; + const item = currentFilteredLibrary[filteredIndex]; + if (!item) return; + const trackId = item.track.id; if (M.selectedLibraryIds.has(trackId)) { M.selectedLibraryIds.delete(trackId); } else { M.selectedLibraryIds.add(trackId); } - lastSelectedLibraryIndex = index; + lastSelectedLibraryIndex = filteredIndex; } M.renderLibrary(); }; @@ -852,19 +859,19 @@ const query = M.librarySearchQuery.toLowerCase(); // Filter library by search query - const filteredLibrary = query + currentFilteredLibrary = query ? M.library.map((track, i) => ({ track, i })).filter(({ track }) => { const title = track.title?.trim() || track.filename; return title.toLowerCase().includes(query); }) : M.library.map((track, i) => ({ track, i })); - if (filteredLibrary.length === 0) { + if (currentFilteredLibrary.length === 0) { container.innerHTML = '
No matches
'; return; } - filteredLibrary.forEach(({ track, i }) => { + currentFilteredLibrary.forEach(({ track, i }, filteredIndex) => { const div = document.createElement("div"); const isCached = M.cachedTracks.has(track.id); const isSelected = M.selectedLibraryIds.has(track.id); @@ -911,7 +918,7 @@ // Click toggles selection div.onclick = (e) => { if (e.target.closest('.track-actions')) return; - M.toggleLibrarySelection(i, e.shiftKey); + M.toggleLibrarySelection(filteredIndex, e.shiftKey); }; // Right-click context menu