fix(subtitles): preserve timings for adjacent repeated text

- Deduplicate only identical subtitle events
- Add regression coverage for repeated text with distinct timings
This commit is contained in:
2026-09-01 00:18:22 -07:00
parent 8f9287806b
commit da71af5769
2 changed files with 23 additions and 2 deletions
+16
View File
@@ -373,6 +373,22 @@ test('handleMineSentenceDigit keeps per-entry timings when subtitle text repeats
}
});
test('subtitle timing history preserves adjacent repeated text with distinct timings', () => {
const tracker = new SubtitleTimingTracker();
try {
tracker.recordSubtitle('same', 1, 2);
tracker.recordSubtitle('same', 3, 4);
assert.deepEqual(tracker.getRecentEntries(2), [
{ displayText: 'same', startTime: 1, endTime: 2, secondaryText: undefined },
{ displayText: 'same', startTime: 3, endTime: 4, secondaryText: undefined },
]);
} finally {
tracker.destroy();
}
});
test('handleMineSentenceDigit joins per-entry secondary subtitles when available', async () => {
const created: Array<{ sentence: string; secondarySub?: string }> = [];
const tracker = new SubtitleTimingTracker();
+7 -2
View File
@@ -67,8 +67,13 @@ export class SubtitleTimingTracker {
// Check for duplicate of most recent entry (deduplicate adjacent repeats)
const lastEntry = this.history[this.history.length - 1];
if (lastEntry && lastEntry.timingKey === timingKey) {
// Update timing to most recent occurrence
if (
lastEntry &&
lastEntry.timingKey === timingKey &&
lastEntry.startTime === startTime &&
lastEntry.endTime === endTime
) {
// Refresh metadata for repeated notifications of the same subtitle event.
lastEntry.startTime = startTime;
lastEntry.endTime = endTime;
lastEntry.secondaryText = displaySecondaryText;