From 091d2efb2e3b6bd85e77ae51ec1f15a0cfb135ba Mon Sep 17 00:00:00 2001 From: jeffvli Date: Thu, 1 Jan 2026 12:41:02 -0800 Subject: [PATCH] fix grid song play behavior (#1477) --- .../item-card/item-card-controls.tsx | 23 ++++++++++++++ .../item-list/helpers/item-list-controls.ts | 30 ++++++++++++++----- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/renderer/components/item-card/item-card-controls.tsx b/src/renderer/components/item-card/item-card-controls.tsx index 512e6bd1d..fff58569e 100644 --- a/src/renderer/components/item-card/item-card-controls.tsx +++ b/src/renderer/components/item-card/item-card-controls.tsx @@ -73,6 +73,29 @@ const createPlayHandler = return; } + const isSongItem = + itemType === LibraryItem.SONG || + itemType === LibraryItem.PLAYLIST_SONG || + (item as { _itemType: LibraryItem })._itemType === LibraryItem.SONG; + + if (isSongItem && controls?.onDoubleClick && internalState) { + const rowId = internalState.extractRowId(item); + + if (rowId) { + const index = internalState.findItemIndex(rowId); + return controls.onDoubleClick({ + event: null, + index, + internalState, + item, + itemType, + meta: { + playType, + }, + }); + } + } + controls?.onPlay?.({ event: e, internalState, diff --git a/src/renderer/components/item-list/helpers/item-list-controls.ts b/src/renderer/components/item-list/helpers/item-list-controls.ts index a6d691a64..ec70e52ec 100644 --- a/src/renderer/components/item-list/helpers/item-list-controls.ts +++ b/src/renderer/components/item-list/helpers/item-list-controls.ts @@ -191,7 +191,7 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs onColumnResized?.(columnId, width); }, - onDoubleClick: ({ internalState, item, itemType }: DefaultItemControlProps) => { + onDoubleClick: ({ internalState, item, itemType, meta }: DefaultItemControlProps) => { if (!item || !internalState) { return; } @@ -212,7 +212,7 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs } } - if (itemType === LibraryItem.SONG) { + if (itemType === LibraryItem.SONG || itemType === LibraryItem.PLAYLIST_SONG) { const data = internalState.getData(); const validSongs = data.filter((d): d is Song => { if (!d || typeof d !== 'object') { @@ -235,17 +235,31 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs return; } - const songsBefore = 100; - const songsAfter = 100; - const startIndex = Math.max(0, clickedIndex - songsBefore); - const endIndex = Math.min(validSongs.length, clickedIndex + songsAfter + 1); - const songsToAdd = validSongs.slice(startIndex, endIndex); + const playType = (meta?.playType as Play) || Play.NOW; + + // For NEXT, LAST, NEXT_SHUFFLE, and LAST_SHUFFLE, only add the clicked song + // For NOW and SHUFFLE, add a range of songs around the clicked song + let songsToAdd: Song[]; + if ( + playType === Play.NEXT || + playType === Play.LAST || + playType === Play.NEXT_SHUFFLE || + playType === Play.LAST_SHUFFLE + ) { + songsToAdd = [item as Song]; + } else { + const songsBefore = 50; + const songsAfter = 50; + const startIndex = Math.max(0, clickedIndex - songsBefore); + const endIndex = Math.min(validSongs.length, clickedIndex + songsAfter + 1); + songsToAdd = validSongs.slice(startIndex, endIndex); + } if (songsToAdd.length === 0) { return; } - player.addToQueueByData(songsToAdd, Play.NOW, item.id); + player.addToQueueByData(songsToAdd, playType, item.id); return; }