From 6d550d850d53c46c56a44f3d91238074d3cfd924 Mon Sep 17 00:00:00 2001 From: Cole Lawrence Date: Sat, 23 Jul 2022 08:18:22 -0400 Subject: [PATCH] fix(studio): capture [space] key after scrubbing fixes P-177 See https://linear.app/theatre/issue/P-177/beginners-scrubbing-the-playhead-from-within-an-iframe-then-[space] --- theatre/studio/src/uiComponents/useDrag.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/theatre/studio/src/uiComponents/useDrag.ts b/theatre/studio/src/uiComponents/useDrag.ts index d9822a0..ad7ad53 100644 --- a/theatre/studio/src/uiComponents/useDrag.ts +++ b/theatre/studio/src/uiComponents/useDrag.ts @@ -250,6 +250,16 @@ export default function useDrag( stateRef.current = {domDragStarted: false} if (opts.shouldPointerLock && !isSafari) document.exitPointerLock() callbacksRef.current.onDragEnd(dragHappened) + + // ensure that the window is focused after a successful drag + // this fixes an issue where after dragging something like the playhead + // through an iframe, you can immediately hit [space] and the animation + // will play, even if you hadn't been focusing in the iframe at the start + // of the drag. + // + // Fixes https://linear.app/theatre/issue/P-177/beginners-scrubbing-the-playhead-from-within-an-iframe-then-[space] + window.focus() + if (!dragHappened) { callbacksRef.current.onClick(e) }