Keep caption edit target current

This commit is contained in:
wizardAEI
2026-04-30 18:00:09 +08:00
parent cace34d3ad
commit 8bfd739eca
9 changed files with 40 additions and 8 deletions
+26 -2
View File
@@ -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<VideoPlaybackRef, VideoPlaybackProps>(
},
ref,
) => {
const { t } = useI18n();
const editCurrentCaptionLabel = t("settings.captions.editCurrent", "Edit current caption");
const videoRef = useRef<HTMLVideoElement | null>(null);
const containerRef = useRef<HTMLDivElement | null>(null);
const appRef = useRef<Application | null>(null);
@@ -484,6 +487,8 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
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<VideoPlaybackRef, VideoPlaybackProps>(
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<VideoPlaybackRef, VideoPlaybackProps>(
}
aria-label={
onEditAutoCaption && !captionEditSession
? "Edit current caption"
? editCurrentCaptionLabel
: undefined
}
ref={captionBoxRef}
@@ -2615,7 +2639,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
1,
activeCaptionLayout.visibleLines.length,
)}
aria-label="Edit current caption"
aria-label={editCurrentCaptionLabel}
style={{
display: "block",
width: `${
+1
View File
@@ -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",
+2 -1
View File
@@ -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",
+2 -1
View File
@@ -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",
+2 -1
View File
@@ -120,7 +120,8 @@
"generateFull": "자막 생성",
"regenerateFull": "자막 다시 생성",
"clearFull": "자막 지우기",
"editSaved": "Caption updated",
"editCurrent": "현재 자막 편집",
"editSaved": "자막이 업데이트되었습니다",
"fontSettings": "글꼴 설정",
"defaultFont": "기본값",
"fontFamily": "글꼴",
+2 -1
View File
@@ -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",
+2 -1
View File
@@ -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",
+1
View File
@@ -120,6 +120,7 @@
"generateFull": "生成字幕",
"regenerateFull": "重新生成字幕",
"clearFull": "清除字幕",
"editCurrent": "编辑当前字幕",
"editSaved": "字幕已更新",
"fontSettings": "字体设置",
"defaultFont": "默认",
+2 -1
View File
@@ -120,7 +120,8 @@
"generateFull": "產生字幕",
"regenerateFull": "重新產生字幕",
"clearFull": "清除字幕",
"editSaved": "Caption updated",
"editCurrent": "編輯目前字幕",
"editSaved": "字幕已更新",
"fontSettings": "字型設定",
"defaultFont": "預設",
"fontFamily": "字型",