Allow scrolling while streaming re: #241

This commit is contained in:
Webifi 2023-07-25 00:21:04 -05:00
parent 0ffdd78863
commit ff3799637b
1 changed files with 17 additions and 1 deletions

View File

@ -246,6 +246,19 @@
chatRequest.updating = true chatRequest.updating = true
chatRequest.updatingMessage = '' 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 { try {
const response = await chatRequest.sendRequest($currentChatMessages, { const response = await chatRequest.sendRequest($currentChatMessages, {
chat, chat,
@ -253,7 +266,8 @@
streaming: chatSettings.stream, streaming: chatSettings.stream,
fillMessage, fillMessage,
onMessageChange: (messages) => { onMessageChange: (messages) => {
scrollToBottom(true) if (doScroll) scrollToBottom(true)
didScroll = !!messages[0]?.content
} }
}) })
await response.promiseToFinish() await response.promiseToFinish()
@ -264,6 +278,8 @@
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
window.removeEventListener('scroll', checkUserScroll)
chatRequest.updating = false chatRequest.updating = false
chatRequest.updatingMessage = '' chatRequest.updatingMessage = ''