@@ -277,39 +277,52 @@ struct ChatHistory: View {
277277 var body : some View {
278278 WithViewStore ( chat, observe: \. history) { viewStore in
279279 ForEach ( viewStore. state, id: \. id) { message in
280- let text = message. text
281-
282- switch message . role {
283- case . user :
284- UserMessage ( id : message . id , text : text , chat : chat )
285- . listRowInsets ( EdgeInsets (
286- top : 0 ,
287- leading : - 8 ,
288- bottom : 0 ,
289- trailing : - 8
290- ) )
291- . padding ( . vertical , 4 )
292- case . assistant :
293- BotMessage (
294- id : message . id ,
295- text : text ,
296- references : message. references ,
297- chat : chat
298- )
280+ ChatHistoryItem ( chat : chat , message : message) . id ( message . id )
281+ }
282+ }
283+ }
284+ }
285+
286+ struct ChatHistoryItem : View {
287+ let chat : StoreOf < Chat >
288+ let message : DisplayedChatMessage
289+ @ State var height : CGFloat = 0
290+ @ State var codeHighlightCacheController = CodeBlockHighlighterCacheController ( )
291+
292+ var body : some View {
293+ let text = message . text
294+
295+ Group {
296+ switch message. role {
297+ case . user :
298+ UserMessage ( id : message . id , text : text , chat : chat )
299299 . listRowInsets ( EdgeInsets (
300300 top: 0 ,
301301 leading: - 8 ,
302302 bottom: 0 ,
303303 trailing: - 8
304304 ) )
305305 . padding ( . vertical, 4 )
306- case . tool:
307- FunctionMessage ( id: message. id, text: text)
308- case . ignored:
309- EmptyView ( )
310- }
306+ case . assistant:
307+ BotMessage (
308+ id: message. id,
309+ text: text,
310+ references: message. references,
311+ chat: chat
312+ )
313+ . listRowInsets ( EdgeInsets (
314+ top: 0 ,
315+ leading: - 8 ,
316+ bottom: 0 ,
317+ trailing: - 8
318+ ) )
319+ . padding ( . vertical, 4 )
320+ case . tool:
321+ FunctionMessage ( id: message. id, text: text)
322+ case . ignored:
323+ EmptyView ( )
311324 }
312- }
325+ } . environment ( \ . codeHighlightCacheController , codeHighlightCacheController )
313326 }
314327}
315328
@@ -563,29 +576,6 @@ struct ChatPanel_EmptyChat_Preview: PreviewProvider {
563576 }
564577}
565578
566- struct ChatCodeSyntaxHighlighter : CodeSyntaxHighlighter {
567- let brightMode : Bool
568- let font : NSFont
569- let colorChange : Color ?
570-
571- init ( brightMode: Bool , font: NSFont , colorChange: Color ? ) {
572- self . brightMode = brightMode
573- self . font = font
574- self . colorChange = colorChange
575- }
576-
577- func highlightCode( _ content: String , language: String ? ) -> Text {
578- let content = highlightedCodeBlock (
579- code: content,
580- language: language ?? " " ,
581- scenario: " chat " ,
582- brightMode: brightMode,
583- font: font
584- )
585- return Text ( AttributedString ( content) )
586- }
587- }
588-
589579struct ChatPanel_InputText_Preview : PreviewProvider {
590580 static var previews : some View {
591581 ChatPanel ( chat: . init(
0 commit comments