update: confort + ui

This commit is contained in:
Tom Boullay
2026-05-10 00:33:18 +01:00
parent 6a394b301e
commit 9969e86e9c
2 changed files with 62 additions and 1 deletions
+45 -1
View File
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { Download, RefreshCw, Save } from "lucide-react"; import { Download, RefreshCw, Save } from "lucide-react";
import type { SubtitleLanguage } from "@/managers/stores/useSettingsStore"; import type { SubtitleLanguage } from "@/managers/stores/useSettingsStore";
import type { import type {
@@ -21,6 +21,11 @@ interface SrtDiagnostic {
errors: string[]; errors: string[];
} }
interface TextRange {
start: number;
end: number;
}
const SRT_VOICES: SrtVoiceOption[] = [ const SRT_VOICES: SrtVoiceOption[] = [
{ id: "narrateur", label: "Narrateur" }, { id: "narrateur", label: "Narrateur" },
{ id: "fermier", label: "Fermier" }, { id: "fermier", label: "Fermier" },
@@ -164,6 +169,23 @@ function getExpectedDialogues(
.sort((a, b) => a.subtitleCueIndex - b.subtitleCueIndex); .sort((a, b) => a.subtitleCueIndex - b.subtitleCueIndex);
} }
function findCueBlockRange(
content: string,
cueIndex: number,
): TextRange | null {
const normalizedContent = content.replace(/\r/g, "");
const cuePattern = new RegExp(`(^|\\n)${cueIndex}\\n`, "m");
const match = normalizedContent.match(cuePattern);
if (!match || match.index === undefined) return null;
const start = match.index + (match[1] ? 1 : 0);
const nextBlockIndex = normalizedContent.indexOf("\n\n", start);
const end = nextBlockIndex === -1 ? normalizedContent.length : nextBlockIndex;
return { start, end };
}
function downloadSrtFile( function downloadSrtFile(
voice: DialogueVoiceId, voice: DialogueVoiceId,
language: SubtitleLanguage, language: SubtitleLanguage,
@@ -198,6 +220,7 @@ async function saveSrtFile(
} }
export function EditorSrtPanel(): React.JSX.Element { export function EditorSrtPanel(): React.JSX.Element {
const textareaRef = useRef<HTMLTextAreaElement>(null);
const [voice, setVoice] = useState<DialogueVoiceId>("narrateur"); const [voice, setVoice] = useState<DialogueVoiceId>("narrateur");
const [language, setLanguage] = useState<SubtitleLanguage>("fr"); const [language, setLanguage] = useState<SubtitleLanguage>("fr");
const [content, setContent] = useState(""); const [content, setContent] = useState("");
@@ -240,6 +263,19 @@ export function EditorSrtPanel(): React.JSX.Element {
} }
} }
function handleJumpToCue(cueIndex: number): void {
const range = findCueBlockRange(content, cueIndex);
if (!range || !textareaRef.current) {
setStatus(`Cue ${cueIndex} introuvable dans le SRT.`);
return;
}
textareaRef.current.focus();
textareaRef.current.setSelectionRange(range.start, range.end);
setStatus(`Cue ${cueIndex} selectionnee dans le SRT.`);
}
useEffect(() => { useEffect(() => {
let mounted = true; let mounted = true;
@@ -353,11 +389,19 @@ export function EditorSrtPanel(): React.JSX.Element {
controls controls
src={selectedDialogue.audio} src={selectedDialogue.audio}
/> />
<button
className="editor-srt-jump-button"
type="button"
onClick={() => handleJumpToCue(selectedDialogue.subtitleCueIndex)}
>
Aller a la cue {selectedDialogue.subtitleCueIndex}
</button>
</div> </div>
)} )}
</div> </div>
<textarea <textarea
ref={textareaRef}
className="editor-srt-textarea" className="editor-srt-textarea"
value={content} value={content}
spellCheck={false} spellCheck={false}
+17
View File
@@ -1506,6 +1506,23 @@ canvas {
height: 34px; height: 34px;
} }
.editor-srt-jump-button {
width: 100%;
padding: 8px 10px;
border: 1px solid #2f2f2f;
border-radius: 12px;
background: #151515;
color: #f2f2f2;
cursor: pointer;
font-size: 0.76rem;
font-weight: 700;
}
.editor-srt-jump-button:hover {
border-color: #ffffff;
background: #202020;
}
.editor-srt-actions { .editor-srt-actions {
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);