@@ -4499,6 +4499,7 @@ table{border-collapse:collapse;width:100%;} th,td{border:1px solid rgba(127,127,
44994499 // If a player exists, never rebuild or switch URLs here — just toggle.
45004500 if let p = ttsPlayer {
45014501 if p. isPlaying { pauseTTS ( ) ; updateNowPlaying ( ) ; return }
4502+ if ( ttsSourceText == nil || ( ttsSourceText? . isEmpty ?? true ) ) { ttsSourceText = text }
45024503 p. play ( ) ; isSpeakingTTS = true ; startTTSTimer ( ) ; updateNowPlaying ( ) ; return
45034504 }
45044505 // No player yet — prepare from cached or generated audio
@@ -4688,6 +4689,10 @@ table{border-collapse:collapse;width:100%;} th,td{border:1px solid rgba(127,127,
46884689 p. enableRate = true
46894690 self . applyTTSRate ( )
46904691 }
4692+ // Ensure source text is present for line highlighting
4693+ if ( self . ttsSourceText == nil || ( self . ttsSourceText? . isEmpty ?? true ) ) {
4694+ self . ttsSourceText = self . conversation. last ( where: { $0. role == . assistant } ) ? . text ?? self . resultText
4695+ }
46914696 self . restoreSavedPositionIfAny ( )
46924697 self . ttsPlayer? . play ( )
46934698 self . isSpeakingTTS = true
@@ -4837,6 +4842,10 @@ table{border-collapse:collapse;width:100%;} th,td{border:1px solid rgba(127,127,
48374842 self . applyTTSRate ( )
48384843 self . multiTTS = self . buildMultiStateIfAny ( startURL: url)
48394844 if let m = self . multiTTS { self . ttsDuration = m. partDurations. reduce ( 0 , + ) } else { self . ttsDuration = p. duration }
4845+ // Ensure source text exists for highlighting
4846+ if ( self . ttsSourceText == nil || ( self . ttsSourceText? . isEmpty ?? true ) ) {
4847+ self . ttsSourceText = self . conversation. last ( where: { $0. role == . assistant } ) ? . text ?? self . resultText
4848+ }
48404849 self . restoreSavedPositionIfAny ( )
48414850 if autoPlay { p. play ( ) ; self . isSpeakingTTS = true ; self . startTTSTimer ( ) } else { self . isSpeakingTTS = false }
48424851 }
0 commit comments