This commit is contained in:
parent
1eebdf9029
commit
c11c434502
2 changed files with 16 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue