Skip to content

Commit

Permalink
fix refresh response postion
Browse files Browse the repository at this point in the history
  • Loading branch information
xqdoo00o authored Aug 22, 2023
1 parent 2f7c24e commit e7d31d7
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4300,15 +4300,43 @@
let userAvatar; // 用户头像
let customDarkOut;
let isCaseSearch; // 搜索是否区分大小写
const isContentBottom = () => messagesEle.scrollHeight - messagesEle.scrollTop - messagesEle.clientHeight < 128;
let controller;
let controllerId;
const findOffsetTop = (ele, target) => { // target is positioned ancestor element
if (ele.offsetParent !== target) return ele.offsetTop + findOffsetTop(ele.offsetParent, target);
else return ele.offsetTop;
}
const findResEle = (ele) => {
if (!ele.classList.contains("response")) return findResEle(ele.parentElement);
else return ele;
}
const isContentBottom = (ele) => {
if (refreshIdx !== void 0) {
return currentResEle.clientHeight + currentResEle.offsetTop > messagesEle.scrollTop + messagesEle.clientHeight
} else {
return messagesEle.scrollHeight - messagesEle.scrollTop - messagesEle.clientHeight < 128;
}
}
const isEleBottom = (ele) => {
return ele.clientHeight + findOffsetTop(ele, messagesEle) > messagesEle.scrollTop + messagesEle.clientHeight;
}
const outOfMsgWindow = (ele) => {
return ele.offsetTop > messagesEle.scrollTop + messagesEle.clientHeight || ele.offsetTop + ele.clientHeight < messagesEle.scrollTop
}
const scrollToBottom = () => {
if (isContentBottom()) {
messagesEle.scrollTo(0, messagesEle.scrollHeight)
if (refreshIdx !== void 0) {
messagesEle.scrollTo(0, currentResEle.clientHeight + currentResEle.offsetTop - messagesEle.clientHeight + 10)
} else {
messagesEle.scrollTo(0, messagesEle.scrollHeight)
}
}
}
const scrollToBottomLoad = (ele) => {
if (messagesEle.scrollHeight - messagesEle.scrollTop - messagesEle.clientHeight < ele.clientHeight + 128) {
messagesEle.scrollTo(0, messagesEle.scrollHeight)
if (!controller || !ele.offsetParent) return;
if (isEleBottom(ele)) {
let resEle = findResEle(ele)
messagesEle.scrollTo(0, resEle.clientHeight + resEle.offsetTop - messagesEle.clientHeight + 10)
}
}
const forceRepaint = (ele) => {
Expand Down Expand Up @@ -5234,10 +5262,6 @@
} else messagesEle.scrollTop = 0;
}
};
const findOffsetTop = (ele, target) => { // target is positioned ancestor element
if (ele.offsetParent !== target) return ele.offsetTop + findOffsetTop(ele.offsetParent, target)
else return ele.offsetTop
};
newChatEle.onclick = () => {
endAll();
addNewChat();
Expand Down Expand Up @@ -6606,8 +6630,6 @@
};
let autoVoiceIdx = 0;
let autoVoiceDataIdx;
let controller;
let controllerId;
let refreshIdx;
let currentResEle;
let progressData = "";
Expand All @@ -6620,6 +6642,7 @@
let isRefresh = refreshIdx !== void 0;
if (isRefresh) {
currentResEle = chatlog.children[systemRole ? refreshIdx - 1 : refreshIdx];
if (outOfMsgWindow(currentResEle)) messagesEle.scrollTo(0, currentResEle.offsetTop)
} else if (!currentResEle) {
currentResEle = createConvEle("response", true, modelVersion);
currentResEle.children[1].innerHTML = "<p class='cursorCls'><br /></p>";
Expand Down Expand Up @@ -6726,9 +6749,7 @@
if (progressData) await delay();
progressData += content;
currentResEle.children[1].innerHTML = md.render(progressData);
if (!isRefresh) {
scrollToBottom();
}
scrollToBottom();
}
}
}
Expand Down

0 comments on commit e7d31d7

Please sign in to comment.