Skip to content

Commit

Permalink
fix #9147
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Sep 18, 2023
1 parent 1eebdf9 commit c11c434
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/src/protyle/scroll/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
const blockElement = hasClosestBlock(targetElement);
if (!blockElement) {
if ((protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" ||
// goHome 时 data-eof 不为 1
protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-index") === "0") &&
(hasClosestByClassName(targetElement, "protyle-background") || hasClosestByClassName(targetElement, "protyle-title"))) {
const inputElement = protyle.scroll.element.querySelector(".b3-slider") as HTMLInputElement;
Expand Down
26 changes: 15 additions & 11 deletions app/src/protyle/util/onGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,26 @@ const setHTML = (options: {
}
protyle.wysiwyg.element.insertAdjacentHTML("beforeend", options.content);
} else if (options.action.includes(Constants.CB_GET_BEFORE)) {
const lastElement = protyle.wysiwyg.element.firstElementChild as HTMLElement;
const lastTop = lastElement.getBoundingClientRect().top;
const firstElement = protyle.wysiwyg.element.firstElementChild as HTMLElement;
const lastTop = firstElement.getBoundingClientRect().top;
protyle.wysiwyg.element.insertAdjacentHTML("afterbegin", options.content);
protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + (lastElement.getBoundingClientRect().top - lastTop);
protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + (firstElement.getBoundingClientRect().top - lastTop);
protyle.scroll.lastScrollTop = protyle.contentElement.scrollTop;
// 动态加载移除
if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select") && !protyle.scroll.keepLazyLoad) {
const removeElements:HTMLElement[] = []
if (protyle.wysiwyg.element.childElementCount > 2 && protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT){
protyle.wysiwyg.element.childNodes.forEach((el)=>{
if((el as HTMLElement).getBoundingClientRect().top > window.innerHeight * 2){
removeElements.push((el as HTMLElement))
}
})
const removeElements: Element[] = []
let childCount = protyle.wysiwyg.element.childElementCount;
let scrollHeight = protyle.contentElement.scrollHeight;
let lastElement = protyle.wysiwyg.element.lastElementChild;
while (childCount > 2 && scrollHeight > REMOVED_OVER_HEIGHT && lastElement.getBoundingClientRect().top > window.innerHeight) {
removeElements.push(lastElement);
lastElement = lastElement.previousElementSibling;
childCount--;
scrollHeight -= lastElement.clientHeight + 8; // 大部分元素的 margin
}
removeElements.forEach((el)=>{el.remove()})
removeElements.forEach((item) => {
item.remove();
});
hideElements(["toolbar"], protyle);
}
} else {
Expand Down

0 comments on commit c11c434

Please sign in to comment.