fix(preview): cull/pick shortcuts target the visible photo, not stale selection

Arrow nav inside preview only updates activePhotoId; selectedPhotos still
points at whatever was selected in the grid before opening preview. X and
S therefore fired against the wrong photo — the toast appeared but the
filmstrip tint for the currently-viewed photo never changed because that
photo was not the cull target.

cullTargets() (and togglePickOnSelection, now sharing it) now prefer
activePhotoId when viewMode === preview.
This commit is contained in:
Claudio
2026-05-11 10:47:02 +02:00
parent a0d275490b
commit 11202a92e7

View File

@@ -219,6 +219,11 @@ export function useKeyboardShortcuts(props: KeyboardShortcutsProps) {
}
/** The set of photo ids the next culling action should apply to.
* - Preview mode → the currently-viewed photo (activePhotoId), since
* arrow nav inside preview only updates activePhotoId and leaves
* selectedPhotos pointing at whatever the user selected in the grid
* before opening preview. Honouring selectedPhotos here would cull
* the wrong photo and the filmstrip tint wouldn't appear to react.
* - Multi-selection → all selected photos
* - Single selection → that one photo
* - No selection but an activePhotoId set (last clicked) → that one
@@ -226,6 +231,9 @@ export function useKeyboardShortcuts(props: KeyboardShortcutsProps) {
*/
const cullTargets = (): string[] => {
const state = usePhotoStore.getState()
if (state.viewMode === 'preview') {
return state.activePhotoId ? [state.activePhotoId] : []
}
if (state.selectedPhotos.length > 0) return state.selectedPhotos
if (state.activePhotoId) return [state.activePhotoId]
return []
@@ -342,13 +350,9 @@ export function useKeyboardShortcuts(props: KeyboardShortcutsProps) {
})
const togglePickOnSelection = () => {
const state = usePhotoStore.getState()
const ids =
state.selectedPhotos.length > 0
? state.selectedPhotos
: state.activePhotoId
? [state.activePhotoId]
: []
// Reuse cullTargets so preview-mode arrow-nav targets the visible
// photo, not the stale grid selection (same fix as X / discard).
const ids = cullTargets()
if (ids.length === 0) {
toast.info('Nothing selected', 'Select photos first, then press S')
return