diff options
| author | sigoden <sigoden@gmail.com> | 2024-05-20 07:56:57 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-20 07:56:57 +0800 |
| commit | 482822da5358a052761dda3767a6cdddca72ac59 (patch) | |
| tree | c9a686fc68fa2517536a08581b1a314c5fb6c2b3 /assets/playground.html | |
| parent | 9b7d93ee84435ac5eeb765662a08eae9cb4140ef (diff) | |
| download | aichat-482822da5358a052761dda3767a6cdddca72ac59.tar.gz | |
fix: webui message body do not autoscroll to bottom sometimes (#525)
Diffstat (limited to 'assets/playground.html')
| -rw-r--r-- | assets/playground.html | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/assets/playground.html b/assets/playground.html index d8c33f7..ccbc488 100644 --- a/assets/playground.html +++ b/assets/playground.html @@ -191,7 +191,7 @@ position: relative; display: flex; flex-direction: column; - width: 100%; + width: calc(100% - 1rem); margin-top: -2px; padding-left: 0.625rem; flex-grow: 1; @@ -825,21 +825,24 @@ }, handleScrollChatBody(event) { - const { scrollTop, clientHeight, scrollHeight } = event.target; - if ((event.target._prevScrollTop || 0) > scrollTop + 1) { + const $chatBody = event.target; + const { scrollTop, clientHeight, scrollHeight, _prevScrollTop = 0 } = $chatBody; + if (scrollTop + clientHeight > scrollHeight - 5) { + this.isShowScrollToBottomBtn = false; + this.shouldScrollChatBodyToBottom = true; + } + if (scrollHeight > clientHeight && _prevScrollTop > 1 && _prevScrollTop > scrollTop + 1) { this.shouldScrollChatBodyToBottom = false; this.isShowScrollToBottomBtn = true; - } else if (this.isShowScrollToBottomBtn && scrollTop + clientHeight > scrollHeight - 5) { - this.isShowScrollToBottomBtn = false; } + $chatBody._prevScrollTop = scrollTop; }, handleScrollToBottom() { const $chatBody = this.$refs["chat-body"]; $chatBody.scrollTop = $chatBody.scrollHeight; - $chatBody._prevScrollTop = $chatBody.scrollTop; this.isShowScrollToBottomBtn = false; - this.autoScrollChatBodyToBottom = true; + this.shouldScrollChatBodyToBottom = true; }, handleShowSidebarBtnClick() { @@ -893,14 +896,11 @@ autoScrollChatBodyToBottom() { if (this.shouldScrollChatBodyToBottom) { - const $chatBody = this.$refs["chat-body"]; - if ($chatBody) { - const { scrollTop, scrollHeight, clientHeight } = $chatBody; - if (scrollTop + clientHeight < scrollHeight - 5) { - $chatBody.scrollTop = scrollHeight; - $chatBody._prevScrollTop = $chatBody.scrollTop; - } + let $chatBody = this.$refs["chat-body"]; + if (!$chatBody) { + $chatBody = document.querySelector('[x-ref="chat-body"]') } + $chatBody.scrollTop = $chatBody.scrollHeight; } }, @@ -925,10 +925,7 @@ async ask() { this.askAbortController = new AbortController(); - this.$nextTick(() => { - this.shouldScrollChatBodyToBottom = true; - this.autoScrollChatBodyToBottom(); - }); + this.shouldScrollChatBodyToBottom = true; const lastMessage = this.messages[this.messages.length - 1]; const body = this.buildBody(); let succeed = false; |
