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.
This commit is contained in:
HanishKVC 2024-05-18 22:21:29 +05:30
parent a1a2f36a45
commit a944ce7cbe

View file

@ -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);
}