Added play/pause keyboard shortcut

This commit is contained in:
Aria Minaei 2021-07-26 14:30:09 +02:00
parent 284f502bdf
commit dfb1a6ff01
2 changed files with 31 additions and 0 deletions

View file

@ -1,6 +1,7 @@
import {useEffect} from 'react' import {useEffect} from 'react'
import getStudio from '@theatre/studio/getStudio' import getStudio from '@theatre/studio/getStudio'
import {cmdIsDown} from '@theatre/studio/utils/keyboardUtils' import {cmdIsDown} from '@theatre/studio/utils/keyboardUtils'
import {getSelectedSequence} from '@theatre/studio/selectors'
export default function useKeyboardShortcuts() { export default function useKeyboardShortcuts() {
const studio = getStudio() const studio = getStudio()
@ -18,6 +19,21 @@ export default function useKeyboardShortcuts() {
studio.undo() 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 { } else {
return return
} }

View file

@ -1,6 +1,9 @@
import type Project from '@theatre/core/projects/Project' 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 type Sheet from '@theatre/core/sheets/Sheet'
import {val} from '@theatre/dataverse' import {val} from '@theatre/dataverse'
import {isSheet, isSheetObject} from '@theatre/shared/instanceTypes'
import {uniq} from 'lodash-es' import {uniq} from 'lodash-es'
import getStudio from './getStudio' import getStudio from './getStudio'
import type {OutlineSelectable, OutlineSelection} from './store/types' import type {OutlineSelectable, OutlineSelection} from './store/types'
@ -67,3 +70,15 @@ export const getSelectedInstanceOfSheetId = (
export function getRegisteredSheetIds(project: Project): string[] { export function getRegisteredSheetIds(project: Project): string[] {
return Object.keys(val(project.sheetTemplatesP)) 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()
}