Allow scrolling while streaming re: #241
This commit is contained in:
parent
0ffdd78863
commit
ff3799637b
|
@ -246,6 +246,19 @@
|
|||
chatRequest.updating = true
|
||||
chatRequest.updatingMessage = ''
|
||||
|
||||
let doScroll = true
|
||||
let didScroll = false
|
||||
|
||||
const checkUserScroll = (e: Event) => {
|
||||
const el = e.target as HTMLElement
|
||||
if (el && e.isTrusted && didScroll) {
|
||||
// from user
|
||||
doScroll = (window.innerHeight + window.scrollY + 10) >= document.body.offsetHeight
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', checkUserScroll)
|
||||
|
||||
try {
|
||||
const response = await chatRequest.sendRequest($currentChatMessages, {
|
||||
chat,
|
||||
|
@ -253,7 +266,8 @@
|
|||
streaming: chatSettings.stream,
|
||||
fillMessage,
|
||||
onMessageChange: (messages) => {
|
||||
scrollToBottom(true)
|
||||
if (doScroll) scrollToBottom(true)
|
||||
didScroll = !!messages[0]?.content
|
||||
}
|
||||
})
|
||||
await response.promiseToFinish()
|
||||
|
@ -265,6 +279,8 @@
|
|||
console.error(e)
|
||||
}
|
||||
|
||||
window.removeEventListener('scroll', checkUserScroll)
|
||||
|
||||
chatRequest.updating = false
|
||||
chatRequest.updatingMessage = ''
|
||||
|
||||
|
|
Loading…
Reference in New Issue