diff --git a/theatre/studio/src/UIRoot/useKeyboardShortcuts.ts b/theatre/studio/src/UIRoot/useKeyboardShortcuts.ts index c80bd05..97c0a7d 100644 --- a/theatre/studio/src/UIRoot/useKeyboardShortcuts.ts +++ b/theatre/studio/src/UIRoot/useKeyboardShortcuts.ts @@ -1,6 +1,7 @@ import {useEffect} from 'react' import getStudio from '@theatre/studio/getStudio' import {cmdIsDown} from '@theatre/studio/utils/keyboardUtils' +import {getSelectedSequence} from '@theatre/studio/selectors' export default function useKeyboardShortcuts() { const studio = getStudio() @@ -18,6 +19,21 @@ export default function useKeyboardShortcuts() { studio.undo() } } + } else if ( + e.key === ' ' && + !e.shiftKey && + !e.metaKey && + !e.altKey && + !e.ctrlKey + ) { + const seq = getSelectedSequence() + if (seq) { + if (seq.playing) { + seq.pause() + } else { + seq.play() + } + } } else { return } diff --git a/theatre/studio/src/selectors.ts b/theatre/studio/src/selectors.ts index dca0ee5..845b3eb 100644 --- a/theatre/studio/src/selectors.ts +++ b/theatre/studio/src/selectors.ts @@ -1,6 +1,9 @@ import type Project from '@theatre/core/projects/Project' +import type Sequence from '@theatre/core/sequences/Sequence' +import type SheetObject from '@theatre/core/sheetObjects/SheetObject' import type Sheet from '@theatre/core/sheets/Sheet' import {val} from '@theatre/dataverse' +import {isSheet, isSheetObject} from '@theatre/shared/instanceTypes' import {uniq} from 'lodash-es' import getStudio from './getStudio' import type {OutlineSelectable, OutlineSelection} from './store/types' @@ -67,3 +70,15 @@ export const getSelectedInstanceOfSheetId = ( export function getRegisteredSheetIds(project: Project): string[] { return Object.keys(val(project.sheetTemplatesP)) } + +export function getSelectedSequence(): undefined | Sequence { + const selectedSheets = uniq( + getOutlineSelection() + .filter((s): s is SheetObject | Sheet => isSheet(s) || isSheetObject(s)) + .map((s) => (isSheetObject(s) ? s.sheet : s)), + ) + const sheet = selectedSheets[0] + if (!sheet) return + + return sheet.getSequence() +}