From 8bfd739ecaf92ebe80349ed160909b27f70456ee Mon Sep 17 00:00:00 2001 From: wizardAEI Date: Thu, 30 Apr 2026 18:00:09 +0800 Subject: [PATCH] Keep caption edit target current --- src/components/video-editor/VideoPlayback.tsx | 28 +++++++++++++++++-- src/i18n/locales/en/settings.json | 1 + src/i18n/locales/es/settings.json | 3 +- src/i18n/locales/fr/settings.json | 3 +- src/i18n/locales/ko/settings.json | 3 +- src/i18n/locales/nl/settings.json | 3 +- src/i18n/locales/pt-BR/settings.json | 3 +- src/i18n/locales/zh-CN/settings.json | 1 + src/i18n/locales/zh-TW/settings.json | 3 +- 9 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/components/video-editor/VideoPlayback.tsx b/src/components/video-editor/VideoPlayback.tsx index bfb8623e..99362abb 100644 --- a/src/components/video-editor/VideoPlayback.tsx +++ b/src/components/video-editor/VideoPlayback.tsx @@ -18,6 +18,7 @@ import { useRef, useState, } from "react"; +import { useI18n } from "@/contexts/I18nContext"; import { getAssetPath, getRenderableAssetUrl, getRenderableVideoUrl } from "@/lib/assetPath"; import { clampMediaTimeToDuration, getMediaSyncPlaybackRate } from "@/lib/mediaTiming"; import { @@ -351,6 +352,8 @@ const VideoPlayback = forwardRef( }, ref, ) => { + const { t } = useI18n(); + const editCurrentCaptionLabel = t("settings.captions.editCurrent", "Edit current caption"); const videoRef = useRef(null); const containerRef = useRef(null); const appRef = useRef(null); @@ -484,6 +487,8 @@ const VideoPlayback = forwardRef( measureText: (text) => measurementContext.measureText(text).width, }); }, [autoCaptionSettings, autoCaptions, currentTime]); + const activeCaptionEditTarget = activeCaptionLayout?.editTarget ?? null; + const activeCaptionEditTargetId = activeCaptionEditTarget?.id ?? null; const isCaptionEditing = captionEditSession !== null; const captionEditDraft = captionEditSession?.draft ?? ""; const captionEditTargetId = captionEditSession?.target.id ?? null; @@ -569,6 +574,25 @@ const VideoPlayback = forwardRef( setCaptionEditSession(null); }, []); + useEffect(() => { + if (!activeCaptionEditTarget) { + return; + } + + setCaptionEditSession((session) => { + if (!session || session.target.id === activeCaptionEditTargetId) { + return session; + } + + const nextSession = { + ...session, + target: activeCaptionEditTarget, + }; + captionEditSessionRef.current = nextSession; + return nextSession; + }); + }, [activeCaptionEditTarget, activeCaptionEditTargetId]); + useEffect(() => { if (!captionEditTargetId) { return; @@ -2519,7 +2543,7 @@ const VideoPlayback = forwardRef( } aria-label={ onEditAutoCaption && !captionEditSession - ? "Edit current caption" + ? editCurrentCaptionLabel : undefined } ref={captionBoxRef} @@ -2615,7 +2639,7 @@ const VideoPlayback = forwardRef( 1, activeCaptionLayout.visibleLines.length, )} - aria-label="Edit current caption" + aria-label={editCurrentCaptionLabel} style={{ display: "block", width: `${ diff --git a/src/i18n/locales/en/settings.json b/src/i18n/locales/en/settings.json index 9a214fef..2ad584e4 100644 --- a/src/i18n/locales/en/settings.json +++ b/src/i18n/locales/en/settings.json @@ -120,6 +120,7 @@ "generateFull": "Generate Captions", "regenerateFull": "Regenerate Captions", "clearFull": "Clear Captions", + "editCurrent": "Edit current caption", "editSaved": "Caption updated", "fontSettings": "Font Settings", "defaultFont": "Default", diff --git a/src/i18n/locales/es/settings.json b/src/i18n/locales/es/settings.json index f1b88cbb..dd2d16b0 100644 --- a/src/i18n/locales/es/settings.json +++ b/src/i18n/locales/es/settings.json @@ -120,7 +120,8 @@ "generateFull": "Generar subtítulos", "regenerateFull": "Regenerar subtítulos", "clearFull": "Borrar subtítulos", - "editSaved": "Caption updated", + "editCurrent": "Editar subtítulo actual", + "editSaved": "Subtítulo actualizado", "fontSettings": "Tipografía", "defaultFont": "Predeterminado", "fontFamily": "Fuente", diff --git a/src/i18n/locales/fr/settings.json b/src/i18n/locales/fr/settings.json index 22feb6fb..1f6335b2 100644 --- a/src/i18n/locales/fr/settings.json +++ b/src/i18n/locales/fr/settings.json @@ -120,7 +120,8 @@ "generateFull": "Générer les sous-titres", "regenerateFull": "Régénérer les sous-titres", "clearFull": "Effacer les sous-titres", - "editSaved": "Caption updated", + "editCurrent": "Modifier le sous-titre actuel", + "editSaved": "Sous-titre mis à jour", "fontSettings": "Paramètres de police", "defaultFont": "Par défaut", "fontFamily": "Police", diff --git a/src/i18n/locales/ko/settings.json b/src/i18n/locales/ko/settings.json index ce8db65a..68907074 100644 --- a/src/i18n/locales/ko/settings.json +++ b/src/i18n/locales/ko/settings.json @@ -120,7 +120,8 @@ "generateFull": "자막 생성", "regenerateFull": "자막 다시 생성", "clearFull": "자막 지우기", - "editSaved": "Caption updated", + "editCurrent": "현재 자막 편집", + "editSaved": "자막이 업데이트되었습니다", "fontSettings": "글꼴 설정", "defaultFont": "기본값", "fontFamily": "글꼴", diff --git a/src/i18n/locales/nl/settings.json b/src/i18n/locales/nl/settings.json index 8b8bd169..3cbaf488 100644 --- a/src/i18n/locales/nl/settings.json +++ b/src/i18n/locales/nl/settings.json @@ -120,7 +120,8 @@ "generateFull": "Ondertiteling genereren", "regenerateFull": "Ondertiteling opnieuw genereren", "clearFull": "Ondertiteling wissen", - "editSaved": "Caption updated", + "editCurrent": "Huidige ondertiteling bewerken", + "editSaved": "Ondertiteling bijgewerkt", "fontSettings": "Lettertype-instellingen", "defaultFont": "Standaard", "fontFamily": "Lettertype", diff --git a/src/i18n/locales/pt-BR/settings.json b/src/i18n/locales/pt-BR/settings.json index dbb751e6..ddde00ae 100644 --- a/src/i18n/locales/pt-BR/settings.json +++ b/src/i18n/locales/pt-BR/settings.json @@ -120,7 +120,8 @@ "generateFull": "Gerar legendas", "regenerateFull": "Gerar legendas novamente", "clearFull": "Limpar legendas", - "editSaved": "Caption updated", + "editCurrent": "Editar legenda atual", + "editSaved": "Legenda atualizada", "fontSettings": "Configurações da fonte", "defaultFont": "Padrão", "fontFamily": "Fonte", diff --git a/src/i18n/locales/zh-CN/settings.json b/src/i18n/locales/zh-CN/settings.json index 92674a8b..1c2ddf35 100644 --- a/src/i18n/locales/zh-CN/settings.json +++ b/src/i18n/locales/zh-CN/settings.json @@ -120,6 +120,7 @@ "generateFull": "生成字幕", "regenerateFull": "重新生成字幕", "clearFull": "清除字幕", + "editCurrent": "编辑当前字幕", "editSaved": "字幕已更新", "fontSettings": "字体设置", "defaultFont": "默认", diff --git a/src/i18n/locales/zh-TW/settings.json b/src/i18n/locales/zh-TW/settings.json index 8edf24d3..1a6b905a 100644 --- a/src/i18n/locales/zh-TW/settings.json +++ b/src/i18n/locales/zh-TW/settings.json @@ -120,7 +120,8 @@ "generateFull": "產生字幕", "regenerateFull": "重新產生字幕", "clearFull": "清除字幕", - "editSaved": "Caption updated", + "editCurrent": "編輯目前字幕", + "editSaved": "字幕已更新", "fontSettings": "字型設定", "defaultFont": "預設", "fontFamily": "字型",