updated queue editing and basic playlist functionality

This commit is contained in:
peterino2 2026-02-06 09:00:23 -08:00
parent 19d98e0cc9
commit 3da3a5e482
1 changed files with 20 additions and 13 deletions

View File

@ -10,7 +10,10 @@
// Last selected index for shift-select range // Last selected index for shift-select range
let lastSelectedQueueIndex = null; 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 // Context menu state
let activeContextMenu = null; let activeContextMenu = null;
@ -341,22 +344,26 @@
M.renderQueue(); M.renderQueue();
}; };
M.toggleLibrarySelection = function(index, shiftKey = false) { M.toggleLibrarySelection = function(filteredIndex, shiftKey = false) {
if (shiftKey && lastSelectedLibraryIndex !== null) { if (shiftKey && lastSelectedLibraryIndex !== null && currentFilteredLibrary.length > 0) {
// Range select: select all between last and current // Range select: select all between last and current in FILTERED list
const start = Math.min(lastSelectedLibraryIndex, index); const start = Math.min(lastSelectedLibraryIndex, filteredIndex);
const end = Math.max(lastSelectedLibraryIndex, index); const end = Math.max(lastSelectedLibraryIndex, filteredIndex);
for (let i = start; i <= end; i++) { 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 { } else {
const trackId = M.library[index].id; const item = currentFilteredLibrary[filteredIndex];
if (!item) return;
const trackId = item.track.id;
if (M.selectedLibraryIds.has(trackId)) { if (M.selectedLibraryIds.has(trackId)) {
M.selectedLibraryIds.delete(trackId); M.selectedLibraryIds.delete(trackId);
} else { } else {
M.selectedLibraryIds.add(trackId); M.selectedLibraryIds.add(trackId);
} }
lastSelectedLibraryIndex = index; lastSelectedLibraryIndex = filteredIndex;
} }
M.renderLibrary(); M.renderLibrary();
}; };
@ -852,19 +859,19 @@
const query = M.librarySearchQuery.toLowerCase(); const query = M.librarySearchQuery.toLowerCase();
// Filter library by search query // Filter library by search query
const filteredLibrary = query currentFilteredLibrary = query
? M.library.map((track, i) => ({ track, i })).filter(({ track }) => { ? M.library.map((track, i) => ({ track, i })).filter(({ track }) => {
const title = track.title?.trim() || track.filename; const title = track.title?.trim() || track.filename;
return title.toLowerCase().includes(query); return title.toLowerCase().includes(query);
}) })
: M.library.map((track, i) => ({ track, i })); : M.library.map((track, i) => ({ track, i }));
if (filteredLibrary.length === 0) { if (currentFilteredLibrary.length === 0) {
container.innerHTML = '<div class="empty">No matches</div>'; container.innerHTML = '<div class="empty">No matches</div>';
return; return;
} }
filteredLibrary.forEach(({ track, i }) => { currentFilteredLibrary.forEach(({ track, i }, filteredIndex) => {
const div = document.createElement("div"); const div = document.createElement("div");
const isCached = M.cachedTracks.has(track.id); const isCached = M.cachedTracks.has(track.id);
const isSelected = M.selectedLibraryIds.has(track.id); const isSelected = M.selectedLibraryIds.has(track.id);
@ -911,7 +918,7 @@
// Click toggles selection // Click toggles selection
div.onclick = (e) => { div.onclick = (e) => {
if (e.target.closest('.track-actions')) return; if (e.target.closest('.track-actions')) return;
M.toggleLibrarySelection(i, e.shiftKey); M.toggleLibrarySelection(filteredIndex, e.shiftKey);
}; };
// Right-click context menu // Right-click context menu