From 6d8947fe7496228c60f4d5fe31f7ce3cb4ace361 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Tue, 2 Dec 2025 00:50:48 -0800 Subject: [PATCH] add double click play handler to song lists --- .../item-list/helpers/item-list-controls.ts | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) 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 4f858d16c..3d059153b 100644 --- a/src/renderer/components/item-list/helpers/item-list-controls.ts +++ b/src/renderer/components/item-list/helpers/item-list-controls.ts @@ -6,7 +6,7 @@ import { ItemListStateItemWithRequiredProperties } from '/@/renderer/components/ import { DefaultItemControlProps, ItemControls } from '/@/renderer/components/item-list/types'; import { ContextMenuController } from '/@/renderer/features/context-menu/context-menu-controller'; import { usePlayer } from '/@/renderer/features/player/context/player-context'; -import { LibraryItem, QueueSong } from '/@/shared/types/domain-types'; +import { LibraryItem, QueueSong, Song } from '/@/shared/types/domain-types'; import { Play, TableColumn } from '/@/shared/types/types'; interface UseDefaultItemListControlsArgs { @@ -212,6 +212,47 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs } } + if (itemType === LibraryItem.SONG) { + const data = internalState.getData(); + const validSongs = data.filter((d): d is Song => { + if (!d || typeof d !== 'object') { + return false; + } + if (!('_itemType' in d)) { + return false; + } + return (d as { _itemType: LibraryItem })._itemType === LibraryItem.SONG; + }); + + if (validSongs.length === 0) { + return; + } + + const clickedSongId = item.id; + const clickedIndex = validSongs.findIndex((song) => song.id === clickedSongId); + + if (clickedIndex === -1) { + 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); + + if (songsToAdd.length === 0) { + return; + } + + player.addToQueueByData(songsToAdd, Play.NOW); + + const targetIndex = clickedIndex - startIndex; + + player.mediaPlayByIndex(targetIndex); + return; + } + if (itemType === LibraryItem.QUEUE_SONG) { const queueSong = item as QueueSong; if (queueSong._uniqueId) {