mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-11 06:42:38 +02:00
Adding a hotkey to jump to the currently playing song (only works without pagination) (#2024)
This commit is contained in:
@@ -16,11 +16,13 @@ export const useListHotkeys = ({
|
||||
focused,
|
||||
internalState,
|
||||
itemType,
|
||||
onShowPlayingSong,
|
||||
}: {
|
||||
controls: ItemControls;
|
||||
focused: boolean;
|
||||
internalState: ItemListStateActions;
|
||||
itemType: LibraryItem;
|
||||
onShowPlayingSong?: () => void;
|
||||
}) => {
|
||||
const { bindings } = useHotkeySettings();
|
||||
const playButtonBehavior = usePlayButtonBehavior();
|
||||
@@ -119,5 +121,11 @@ export const useListHotkeys = ({
|
||||
}
|
||||
},
|
||||
],
|
||||
[
|
||||
bindings.listShowPlayingSong.hotkey,
|
||||
() => {
|
||||
onShowPlayingSong?.();
|
||||
},
|
||||
],
|
||||
]);
|
||||
};
|
||||
|
||||
@@ -66,6 +66,7 @@ import {
|
||||
ItemTableListColumnConfig,
|
||||
} from '/@/renderer/components/item-list/types';
|
||||
import { PlayerContext, usePlayer } from '/@/renderer/features/player/context/player-context';
|
||||
import { usePlayerStore } from '/@/renderer/store';
|
||||
import { animationProps } from '/@/shared/components/animations/animation-props';
|
||||
import { useFocusWithin } from '/@/shared/hooks/use-focus-within';
|
||||
import { useMergedRef } from '/@/shared/hooks/use-merged-ref';
|
||||
@@ -1596,11 +1597,22 @@ const BaseItemTableList = ({
|
||||
],
|
||||
);
|
||||
|
||||
const onShowPlayingSong = useCallback(() => {
|
||||
const targetId = usePlayerStore.getState().getCurrentSong()?.id;
|
||||
if (!targetId) return;
|
||||
const index =
|
||||
getItemIndex?.(targetId) ??
|
||||
data.findIndex((item) => (item as null | { id?: string })?.id === targetId);
|
||||
if (index === undefined || index < 0) return;
|
||||
handleRef.current?.scrollToIndex(index, { align: 'center', behavior: 'auto' });
|
||||
}, [data, getItemIndex]);
|
||||
|
||||
useListHotkeys({
|
||||
controls,
|
||||
focused,
|
||||
internalState,
|
||||
itemType,
|
||||
onShowPlayingSong,
|
||||
});
|
||||
|
||||
const tableConfigValue = useMemo<ItemTableListConfig>(
|
||||
|
||||
Reference in New Issue
Block a user