diff --git a/KDChat/Views/ChatBufferView.swift b/KDChat/Views/ChatBufferView.swift index b0c6baf..5f42f31 100644 --- a/KDChat/Views/ChatBufferView.swift +++ b/KDChat/Views/ChatBufferView.swift @@ -38,6 +38,11 @@ struct ChatBufferView: View { } .padding() } + .onChange(of: isInputFocused) { _, focused in + if focused, let last = messages.last { + proxy.scrollTo(last.persistentModelID, anchor: .bottom) + } + } .onChange(of: messages.count) { guard let last = messages.last, last.sessionId == manager.sessionId else { return } Task { @MainActor in diff --git a/KDChat/Views/DMConversationView.swift b/KDChat/Views/DMConversationView.swift index bf56813..20e4f00 100644 --- a/KDChat/Views/DMConversationView.swift +++ b/KDChat/Views/DMConversationView.swift @@ -34,6 +34,11 @@ struct DMConversationView: View { } .padding() } + .onChange(of: isInputFocused) { _, focused in + if focused, let last = messages.last { + proxy.scrollTo(last.persistentModelID, anchor: .bottom) + } + } .onChange(of: messages.count) { guard let last = messages.last, last.sessionId == manager.sessionId else { return } Task { @MainActor in