From b122e4ff05b8f21e31aee525c73df5fed3da7dd6 Mon Sep 17 00:00:00 2001 From: mrapple <86132722+literallytwo@users.noreply.github.com> Date: Sat, 10 May 2025 22:34:02 +0100 Subject: [PATCH] i have space! the spacebar didnt work for speeding up the video because it just paused it, now it works! --- .../player/internals/KeyboardEvents.tsx | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/components/player/internals/KeyboardEvents.tsx b/src/components/player/internals/KeyboardEvents.tsx index b4f079f5..81172f45 100644 --- a/src/components/player/internals/KeyboardEvents.tsx +++ b/src/components/player/internals/KeyboardEvents.tsx @@ -153,13 +153,8 @@ export function KeyboardEvents() { if (next) dataRef.current.display?.setPlaybackRate(next); } - // Handle spacebar hold for 2x speed - if ( - k === " " && - !dataRef.current.isSpaceHeldRef.current && - !dataRef.current.mediaPlaying.isPaused && - !dataRef.current.isPendingBoostRef.current - ) { + // Handle spacebar press for play/pause and hold for 2x speed + if (k === " ") { // Skip if a button is targeted if ( evt.target && @@ -168,9 +163,20 @@ export function KeyboardEvents() { return; } - // Prevent the default spacebar behavior (play/pause) + // Prevent the default spacebar behavior evt.preventDefault(); + // If already paused, play the video and return + if (dataRef.current.mediaPlaying.isPaused) { + dataRef.current.display?.play(); + return; + } + + // If we're already holding space, don't trigger boost again + if (dataRef.current.isSpaceHeldRef.current) { + return; + } + // Save current rate dataRef.current.previousRateRef.current = dataRef.current.mediaPlaying.playbackRate; @@ -220,10 +226,10 @@ export function KeyboardEvents() { // Utils if (keyL === "f") dataRef.current.display?.toggleFullscreen(); - if ( - (k === " " || keyL === "k") && - !dataRef.current.isSpaceHeldRef.current - ) { + + // Remove duplicate spacebar handler that was conflicting + // with our improved implementation + if (keyL === "k" && !dataRef.current.isSpaceHeldRef.current) { if ( evt.target && (evt.target as HTMLInputElement).nodeName === "BUTTON"