From a944ce7cbe809d1dd6ccbc8441efce23f7dad34c Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Sat, 18 May 2024 22:21:29 +0530 Subject: [PATCH] SimpleChat:JS: Try ensure the last entry in chat is visible Needed because now only the chat div is scrollable and not the full page. In last commit the chat div size was fixed to 75% vertical height, so the full page no longer scrolls, so the old bring user-input element to view wont work, instead now the last element in the chat div should be brought into view. --- examples/server/public_simplechat/simplechat.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index b208723fe..fed5720c7 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -45,11 +45,16 @@ class SimpleChat { if (bClear) { div.replaceChildren(); } + let last = undefined; for(const x of this.xchat) { let entry = document.createElement("p"); entry.className = `role-${x.role}`; entry.innerText = `${x.role}: ${x.content}`; div.appendChild(entry); + last = entry; + } + if (last !== undefined) { + last.scrollIntoView(true); } } @@ -139,7 +144,6 @@ async function handle_submit(inputSystem, inputUser, divChat, apiEP) { theBody = gChat.request_prompt_jsonstr(); } - inputUser.scrollIntoView(true); inputUser.value = "working..."; inputUser.disabled = true; console.debug(`DBUG:HandleSubmit:${theUrl}:ReqBody:${theBody}`); @@ -174,7 +178,6 @@ async function handle_submit(inputSystem, inputUser, divChat, apiEP) { if ((apiEP == ApiEP.Completion) && (gbCompletionFreshChatAlways)) { gChat.xchat.length = 0; } - inputUser.scrollIntoView(true); }