diff --git a/app/packages/looker/src/elements/common/actions.ts b/app/packages/looker/src/elements/common/actions.ts index 22fc074d3f..c498abd797 100644 --- a/app/packages/looker/src/elements/common/actions.ts +++ b/app/packages/looker/src/elements/common/actions.ts @@ -2,6 +2,7 @@ * Copyright 2017-2024, Voxel51, Inc. */ +import { is } from "immutable"; import { SCALE_FACTOR } from "../../constants"; import { ImaVidFramesController } from "../../lookers/imavid/controller"; import { @@ -553,23 +554,41 @@ export const resetPlaybackRate: Control = { }, }; -const seekTo: Control = { +const seekTo: Control = { title: "Seek to", detail: "Seek to 0%, 10%, 20%... of the video", shortcut: "0-9", eventKeys: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], action: (update, dispatchEvent, eventKey) => { - update(({ duration, config: { frameRate, support }, lockedToSupport }) => { - const frameCount = getFrameNumber(duration, duration, frameRate); - const total = lockedToSupport ? support[1] - support[0] : frameCount; - const base = lockedToSupport ? support[0] : 1; - + update((state: ImaVidState | VideoState) => { + const isImavid = (state.config as ImaVidConfig) + .frameStoreController as ImaVidFramesController; + const frameName = isImavid ? "currentFrameNumber" : "frameNumber"; + let total = 0; + let base = 0; + if (isImavid) { + const { + config: { + frameStoreController: { totalFrameCount }, + }, + currentFrameNumber, + } = state as ImaVidState; + total = totalFrameCount; + base = currentFrameNumber < totalFrameCount ? currentFrameNumber : 1; + } else { + const { + lockedToSupport, + config: { support, frameRate }, + duration, + } = state as VideoState; + const frameCount = getFrameNumber(duration, duration, frameRate); + total = lockedToSupport ? support[1] - support[0] : frameCount; + base = lockedToSupport ? support[0] : 1; + } + const position = Math.round((parseInt(eventKey, 10) / 10) * total) + base; dispatchEvent("options", { showJSON: false }); return { - frameNumber: Math.max( - 1, - Math.round((parseInt(eventKey, 10) / 10) * total) + base - ), + [frameName]: Math.min(total, Math.max(1, position)), options: { showJSON: false }, }; }); @@ -594,66 +613,70 @@ export const supportLock: Control = { }, }; -const videoEscape: Control = { +const videoEscape: Control = { title: "Escape context", shortcut: "Esc", eventKeys: "Escape", detail: "Escape the current context", alwaysHandle: true, - action: (update, dispatchEvent, eventKey) => { - update( - ({ + action: (update, dispatchEvent) => { + update((state: ImaVidState | VideoState) => { + const isImavid = (state.config as ImaVidConfig) + .frameStoreController as ImaVidFramesController; + + const frameName = isImavid ? "currentFrameNumber" : "frameNumber"; + + const { hasDefaultZoom, showOptions, - frameNumber, config: { support }, options: { showHelp, showJSON, selectedLabels }, lockedToSupport, - }) => { - if (showHelp) { - dispatchEvent("panels", { showHelp: "close" }); - return { showHelp: "close" }; - } + } = state as VideoState; - if (showOptions) { - return { showOptions: false }; - } + if (showHelp) { + dispatchEvent("panels", { showHelp: "close" }); + return { showHelp: "close" }; + } - if (showJSON) { - dispatchEvent("panels", { showJSON: "close" }); - dispatchEvent("options", { showJSON: false }); - return { options: { showJSON: false } }; - } + if (showOptions) { + return { showOptions: false }; + } - if (!lockedToSupport && Boolean(support)) { - return { - frameNumber: support[0], - lockedToSupport: true, - }; - } + if (showJSON) { + dispatchEvent("panels", { showJSON: "close" }); + dispatchEvent("options", { showJSON: false }); + return { options: { showJSON: false } }; + } - if (!hasDefaultZoom) { - return { - setZoom: true, - }; - } + if (!lockedToSupport && Boolean(support) && !isImavid) { + return { + frameNumber: support[0], + lockedToSupport: true, + }; + } - if (frameNumber !== 1) { - return { - frameNumber: 1, - playing: false, - }; - } + if (!hasDefaultZoom) { + return { + setZoom: true, + }; + } - if (selectedLabels.length) { - dispatchEvent("clear"); - return {}; - } + if (state[frameName] !== 1) { + return { + [frameName]: 1, + playing: false, + }; + } - dispatchEvent("close"); + if (selectedLabels.length) { + dispatchEvent("clear"); return {}; } - ); + + dispatchEvent("close"); + return {}; + }); }, };