diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 1b8cc76b9..5dd91669f 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1,4 +1,6 @@ { + "crossKeepLazyLoad": "Cross-page multi-selection needs to select [Keep Loaded Content] in the more menu", + "keepLazyLoad": "Keep loaded content", "localSnapshot": "Local Snapshot", "localTagSnapshot": "Local Tag Snapshot", "cloudTagSnapshot": "Cloud Tag Snapshot", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 6dc4d00d9..0207ae6e6 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1,4 +1,6 @@ { + "crossKeepLazyLoad": "La selección múltiple entre páginas debe seleccionar [Mantener contenido cargado] en el menú más", + "keepLazyLoad": "Mantener el contenido cargado", "localSnapshot": "Instantánea local", "localTagSnapshot": "Instantánea de etiqueta local", "cloudTagSnapshot": "Instantánea de etiquetas en la nube", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index ce58811ff..735c25f7c 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1,4 +1,6 @@ { + "crossKeepLazyLoad": "La multi-sélection sur plusieurs pages doit sélectionner [Conserver le contenu chargé] dans le menu plus", + "keepLazyLoad": "Conserver le contenu chargé", "localSnapshot": "Instantané local", "localTagSnapshot": "Instantané de balise locale", "cloudTagSnapshot": "Instantané de balise cloud", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 5b782f776..ae76a5f63 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1,4 +1,6 @@ { + "crossKeepLazyLoad": "跨頁多選需在更多菜單中選中【保持已加載內容】", + "keepLazyLoad": "保持已加載的內容", "localSnapshot": "本地快照", "localTagSnapshot": "本地標記的快照", "cloudTagSnapshot": "雲端標記的快照", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 1f73ea0e5..ccf2bdd99 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1,4 +1,6 @@ { + "crossKeepLazyLoad": "跨页多选需在更多菜单中选中【保持已加载内容】", + "keepLazyLoad": "保持已加载的内容", "localSnapshot": "本地快照", "localTagSnapshot": "本地标记的快照", "cloudTagSnapshot": "云端标记的快照", diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts index 5f355aecd..2f67a76d4 100644 --- a/app/src/protyle/breadcrumb/index.ts +++ b/app/src/protyle/breadcrumb/index.ts @@ -214,36 +214,6 @@ export class Breadcrumb { } } }).element); - window.siyuan.menus.menu.append(new MenuItem({ - label: window.siyuan.languages.optimizeTypography, - click: () => { - fetchPost("/api/format/autoSpace", { - id: protyle.block.rootID - }, () => { - /// #if MOBILE - fetchPost("/api/filetree/getDoc", { - id: protyle.block.id, - mode: 0, - size: Constants.SIZE_GET, - }, getResponse => { - onGet(getResponse, protyle, [Constants.CB_GET_FOCUS]); - }); - /// #else - getAllModels().editor.forEach(item => { - if (item.editor.protyle.block.rootID === protyle.block.rootID) { - fetchPost("/api/filetree/getDoc", { - id: item.editor.protyle.block.rootID, - mode: 0, - size: Constants.SIZE_GET, - }, getResponse => { - onGet(getResponse, item.editor.protyle, [Constants.CB_GET_FOCUS]); - }); - } - }); - /// #endif - }); - } - }).element); window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.netImg2LocalAsset, click: () => { @@ -274,6 +244,45 @@ export class Breadcrumb { }); } }).element); + window.siyuan.menus.menu.append(new MenuItem({ + label: window.siyuan.languages.optimizeTypography, + click: () => { + fetchPost("/api/format/autoSpace", { + id: protyle.block.rootID + }, () => { + /// #if MOBILE + fetchPost("/api/filetree/getDoc", { + id: protyle.block.id, + mode: 0, + size: Constants.SIZE_GET, + }, getResponse => { + onGet(getResponse, protyle, [Constants.CB_GET_FOCUS]); + }); + /// #else + getAllModels().editor.forEach(item => { + if (item.editor.protyle.block.rootID === protyle.block.rootID) { + fetchPost("/api/filetree/getDoc", { + id: item.editor.protyle.block.rootID, + mode: 0, + size: Constants.SIZE_GET, + }, getResponse => { + onGet(getResponse, item.editor.protyle, [Constants.CB_GET_FOCUS]); + }); + } + }); + /// #endif + }); + } + }).element); + if (!protyle.scroll?.element.classList.contains("fn__none")) { + window.siyuan.menus.menu.append(new MenuItem({ + current: protyle.scroll.keepLazyLoad, + label: window.siyuan.languages.keepLazyLoad, + click: () => { + protyle.scroll.keepLazyLoad = !protyle.scroll.keepLazyLoad; + } + }).element); + } window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({ icon: "iconRefresh", diff --git a/app/src/protyle/scroll/index.ts b/app/src/protyle/scroll/index.ts index a900c838c..41735a98a 100644 --- a/app/src/protyle/scroll/index.ts +++ b/app/src/protyle/scroll/index.ts @@ -7,6 +7,7 @@ export class Scroll { private inputElement: HTMLInputElement; public blockSize: number; public lastScrollTop: number; + public keepLazyLoad: boolean; constructor(protyle: IProtyle) { const divElement = document.createElement("div"); @@ -14,6 +15,7 @@ export class Scroll { divElement.className = "fn__none protyle-scroll b3-tooltips b3-tooltips__s"; divElement.setAttribute("aria-label", "Blocks 1/1"); this.element = divElement; + this.keepLazyLoad = false; if (!protyle.options.render.scroll) { this.element.classList.add("fn__none"); } diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index 2aa885c86..b91bf536e 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -104,7 +104,7 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt const REMOVED_OVER_HEIGHT = protyle.contentElement.clientHeight * 8; if (options.action.includes(Constants.CB_GET_APPEND)) { // 动态加载移除 - if (protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT) { + if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select") && !protyle.scroll.keepLazyLoad && protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT) { preventScroll(protyle); let removeElement = protyle.wysiwyg.element.firstElementChild as HTMLElement; const removeElements = []; @@ -130,9 +130,11 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt protyle.wysiwyg.element.insertAdjacentHTML("afterbegin", options.content); protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + (lastElement.getBoundingClientRect().top - lastTop); // 动态加载移除 - while (protyle.wysiwyg.element.childElementCount > 2 && protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT && - protyle.wysiwyg.element.lastElementChild.getBoundingClientRect().top > window.innerHeight) { - protyle.wysiwyg.element.lastElementChild.remove(); + if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select") && !protyle.scroll.keepLazyLoad) { + while (protyle.wysiwyg.element.childElementCount > 2 && protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT && + protyle.wysiwyg.element.lastElementChild.getBoundingClientRect().top > window.innerHeight) { + protyle.wysiwyg.element.lastElementChild.remove(); + } } } else { protyle.wysiwyg.element.innerHTML = options.content; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index f45102afc..7b4457379 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1813,6 +1813,10 @@ export class WYSIWYG { shiftStartElement = undefined; } else { const ids: string[] = []; + if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select") && protyle.scroll && !protyle.scroll.element.classList.contains("fn__none") && !protyle.scroll.keepLazyLoad && + (startElement.getBoundingClientRect().top < -protyle.contentElement.clientHeight * 2 || endElement.getBoundingClientRect().bottom > protyle.contentElement.clientHeight * 2)) { + showMessage(window.siyuan.languages.crossKeepLazyLoad); + } selectElements.forEach(item => { item.classList.add("protyle-wysiwyg--select"); ids.push(item.getAttribute("data-node-id"));