fix: guarantee main-first cueLine ordering for same index

Add stable sort to ensure the main vocals cueLine (empty role)
always appears before other roles when multiple cueLines share
the same line index. Previously relied on source document order
which is not guaranteed across all TTML files.
This commit is contained in:
ranokay 2026-02-23 11:22:00 +02:00
parent 944401cae3
commit 9279338664
No known key found for this signature in database

View File

@ -530,6 +530,11 @@ func buildStructuredLyric(mf *model.MediaFile, lyrics model.Lyrics, enhanced boo
})
}
// Ensure main vocals (empty role) always comes first
sort.SliceStable(roleOrder, func(i, j int) bool {
return roleOrder[i] == "" && roleOrder[j] != ""
})
// Create a separate CueLine for each role group
for _, role := range roleOrder {
cues := cuesByRole[role]