diff --git a/app/src/asset/index.ts b/app/src/asset/index.ts index ffc27bdf6..02eeade04 100644 --- a/app/src/asset/index.ts +++ b/app/src/asset/index.ts @@ -503,7 +503,7 @@ export class Asset extends Model { /// #if !BROWSER setModelsHash(); /// #endif - }, Constants.TIMEOUT_BLOCKLOAD); + }, Constants.TIMEOUT_LOAD); /// #endif } } diff --git a/app/src/constants.ts b/app/src/constants.ts index 0bc967adc..8a0ec171c 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -85,10 +85,9 @@ export abstract class Constants { // timeout public static readonly TIMEOUT_DBLCLICK = 190; - public static readonly TIMEOUT_SEARCH = 300; public static readonly TIMEOUT_INPUT = 256; - public static readonly TIMEOUT_BLOCKLOAD = 300; - public static readonly TIMEOUT_TRANSITION = 150; + public static readonly TIMEOUT_LOAD = 300; + public static readonly TIMEOUT_TRANSITION = 300; // id public static readonly HELP_PATH = { diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 0352383fe..2856ed79a 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -434,48 +434,56 @@ const newTab = (options: IOpenFileOptions) => { return tab; }; -export const updatePanelByEditor = (protyle?: IProtyle, focus = true, pushBackStack = false, reload = false) => { +export const updatePanelByEditor = (options: { + protyle?: IProtyle, + focus: boolean, + pushBackStack: boolean, + reload: boolean, + resize: boolean +}) => { let title = window.siyuan.languages.siyuanNote; - if (protyle && protyle.path) { + if (options.protyle && options.protyle.path) { // https://ld246.com/article/1637636106054/comment/1641485541929#comments - if (protyle.element.classList.contains("fn__none") || - (!hasClosestByClassName(protyle.element, "layout__wnd--active") && + if (options.protyle.element.classList.contains("fn__none") || + (!hasClosestByClassName(options.protyle.element, "layout__wnd--active") && document.querySelector(".layout__wnd--active") // https://github.com/siyuan-note/siyuan/issues/4414 ) ) { return; } - title = protyle.title.editElement.textContent; - resize(protyle); + title = options.protyle.title.editElement.textContent; + if (options.resize) { + resize(options.protyle); + } if (focus) { - if (protyle.toolbar.range) { - focusByRange(protyle.toolbar.range); - countSelectWord(protyle.toolbar.range, protyle.block.rootID); - if (pushBackStack && protyle.preview.element.classList.contains("fn__none")) { - pushBack(protyle, protyle.toolbar.range); + if (options.protyle.toolbar.range) { + focusByRange(options.protyle.toolbar.range); + countSelectWord(options.protyle.toolbar.range, options.protyle.block.rootID); + if (options.pushBackStack && options.protyle.preview.element.classList.contains("fn__none")) { + pushBack(options.protyle, options.protyle.toolbar.range); } } else { - focusBlock(protyle.wysiwyg.element.firstElementChild); - if (pushBackStack && protyle.preview.element.classList.contains("fn__none")) { - pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild); + focusBlock(options.protyle.wysiwyg.element.firstElementChild); + if (options.pushBackStack && options.protyle.preview.element.classList.contains("fn__none")) { + pushBack(options.protyle, undefined, options.protyle.wysiwyg.element.firstElementChild); } - countBlockWord([], protyle.block.rootID); + countBlockWord([], options.protyle.block.rootID); } } - if (window.siyuan.config.fileTree.alwaysSelectOpenedFile && protyle) { + if (window.siyuan.config.fileTree.alwaysSelectOpenedFile && options.protyle) { const fileModel = getDockByType("file")?.data.file; if (fileModel instanceof Files) { - const target = fileModel.element.querySelector(`li[data-path="${protyle.path}"]`); + const target = fileModel.element.querySelector(`li[data-path="${options.protyle.path}"]`); if (!target || (target && !target.classList.contains("b3-list-item--focus"))) { - fileModel.selectItem(protyle.notebookId, protyle.path); + fileModel.selectItem(options.protyle.notebookId, options.protyle.path); } } } } // 切换页签或关闭所有页签时,需更新对应的面板 const models = getAllModels(); - updateOutline(models, protyle, reload); - updateBacklinkGraph(models, protyle); + updateOutline(models, options.protyle, options.reload); + updateBacklinkGraph(models, options.protyle); setTitle(title); }; diff --git a/app/src/layout/Tab.ts b/app/src/layout/Tab.ts index f387b4b37..d8f298ada 100644 --- a/app/src/layout/Tab.ts +++ b/app/src/layout/Tab.ts @@ -102,7 +102,7 @@ export class Tab { (event.clientX < 0 || event.clientY < 0 || event.clientX > window.innerWidth || event.clientY > window.innerHeight)) { openNewWindow(this); } - }, Constants.TIMEOUT_BLOCKLOAD); // 等待主进程发送关闭消息 + }, Constants.TIMEOUT_LOAD); // 等待主进程发送关闭消息 /// #endif window.siyuan.dragElement = undefined; if (event.dataTransfer.dropEffect === "none") { diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index ac9294f93..5b54237e5 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -484,10 +484,22 @@ export class Wnd { } // focusin 触发前,layout__wnd--active 和 tab 已设置,需在调用里面更新 if (update) { - updatePanelByEditor(currentTab.model.editor.protyle, true, pushBack); + updatePanelByEditor({ + protyle: currentTab.model.editor.protyle, + focus: true, + pushBackStack: pushBack, + reload: false, + resize: true, + }); } } else { - updatePanelByEditor(undefined, false); + updatePanelByEditor({ + protyle: undefined, + focus: false, + pushBackStack: false, + reload: false, + resize: true, + }); } } @@ -685,12 +697,24 @@ export class Wnd { // 关闭分屏页签后光标消失 const editors = getAllModels().editor; if (editors.length === 0) { - updatePanelByEditor(); + updatePanelByEditor({ + protyle: undefined, + focus: true, + pushBackStack: false, + reload: false, + resize: true, + }); } else { editors.forEach(item => { if (!item.element.classList.contains("fn__none")) { setPanelFocus(item.parent.parent.headersElement.parentElement.parentElement); - updatePanelByEditor(item.editor.protyle, true, true); + updatePanelByEditor({ + protyle: item.editor.protyle, + focus: true, + pushBackStack: true, + reload: false, + resize: true, + }); return; } }); @@ -719,7 +743,7 @@ export class Wnd { item.headElement.setAttribute("style", "max-width: 0px;"); setTimeout(() => { item.headElement.remove(); - }, Constants.TIMEOUT_TRANSITION); + }, 200); } else { item.headElement.remove(); } diff --git a/app/src/layout/dock/Backlink.ts b/app/src/layout/dock/Backlink.ts index 941846d02..95c8ced76 100644 --- a/app/src/layout/dock/Backlink.ts +++ b/app/src/layout/dock/Backlink.ts @@ -641,6 +641,6 @@ export class Backlink extends Model { setTimeout(() => { this.tree.element.scrollTop = this.status[this.blockId].scrollTop; this.mTree.element.scrollTop = this.status[this.blockId].mScrollTop; - }, Constants.TIMEOUT_BLOCKLOAD); + }, Constants.TIMEOUT_LOAD); } } diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts index bd4572280..b4571227e 100644 --- a/app/src/layout/util.ts +++ b/app/src/layout/util.ts @@ -400,7 +400,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => { action: idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], zoomIn: idZoomIn.isZoomIn }); - }, Constants.TIMEOUT_BLOCKLOAD); + }, Constants.TIMEOUT_LOAD); } }; diff --git a/app/src/mobile/menu/search.ts b/app/src/mobile/menu/search.ts index 5716fb1e1..3ce6da4f7 100644 --- a/app/src/mobile/menu/search.ts +++ b/app/src/mobile/menu/search.ts @@ -242,7 +242,7 @@ const updateSearchResult = (config: ISearchOption, element: Element) => { } }); } - }, Constants.TIMEOUT_SEARCH); + }, Constants.TIMEOUT_INPUT); }; const initSearchEvent = (element: Element, config: ISearchOption) => { diff --git a/app/src/protyle/export/util.ts b/app/src/protyle/export/util.ts index 40aa471af..fd6623793 100644 --- a/app/src/protyle/export/util.ts +++ b/app/src/protyle/export/util.ts @@ -69,7 +69,7 @@ export const exportImage = (id: string) => { }); }); }); - }, Constants.TIMEOUT_TRANSITION); + }, Constants.TIMEOUT_LOAD); }); const previewElement = exportDialog.element.querySelector("#preview") as HTMLElement; const foldElement = (exportDialog.element.querySelector("#keepFold") as HTMLInputElement); diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index ac4e417bd..afc4d9a20 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -60,7 +60,13 @@ export class Title { this.editElement.addEventListener("click", () => { if (protyle.model) { setPanelFocus(protyle.model.element.parentElement.parentElement); - updatePanelByEditor(protyle, false); + updatePanelByEditor({ + protyle: protyle, + focus: false, + pushBackStack: false, + reload: false, + resize: false, + }); } protyle.toolbar?.element.classList.add("fn__none"); }); diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index c707bc990..e1310cc12 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -116,7 +116,13 @@ export class Protyle { /// #if !MOBILE if (data.cmd === "heading2doc") { // 文档标题互转后,需更新大纲 - updatePanelByEditor(this.protyle, false, false, true); + updatePanelByEditor({ + protyle: this.protyle, + focus: false, + pushBackStack: false, + reload: true, + resize: false + }); } /// #endif } @@ -200,7 +206,13 @@ export class Protyle { if (mergedOptions.action?.includes(Constants.CB_GET_FOCUS)) { setPanelFocus(this.protyle.model.element.parentElement.parentElement); } - updatePanelByEditor(this.protyle, false); + updatePanelByEditor({ + protyle: this.protyle, + focus: false, + pushBackStack: false, + reload: false, + resize: false + }); /// #endif } @@ -217,7 +229,13 @@ export class Protyle { return; } setPanelFocus(this.protyle.model.element.parentElement.parentElement); - updatePanelByEditor(this.protyle, false); + updatePanelByEditor({ + protyle: this.protyle, + focus: false, + pushBackStack: false, + reload: false, + resize: false, + }); } else { // 悬浮层应移除其余面板高亮,否则按键会被面板监听到 document.querySelectorAll(".layout__tab--active").forEach(item => { diff --git a/app/src/protyle/markdown/mermaidRender.ts b/app/src/protyle/markdown/mermaidRender.ts index 7632143e1..c8ba688cc 100644 --- a/app/src/protyle/markdown/mermaidRender.ts +++ b/app/src/protyle/markdown/mermaidRender.ts @@ -73,7 +73,7 @@ const initMermaid = (mermaidElements: Element[]) => { renderElement.textContent = Lute.UnEscapeHTMLStr(item.getAttribute("data-content")); setTimeout(() => { mermaid.init(undefined, renderElement); - }, Constants.TIMEOUT_BLOCKLOAD * index); + }, Constants.TIMEOUT_LOAD * index); item.setAttribute("data-render", "true"); renderElement.setAttribute("contenteditable", "false"); if (!item.textContent.endsWith(Constants.ZWSP)) { diff --git a/app/src/protyle/scroll/event.ts b/app/src/protyle/scroll/event.ts index 186099cf5..691ca4f1e 100644 --- a/app/src/protyle/scroll/event.ts +++ b/app/src/protyle/scroll/event.ts @@ -55,7 +55,7 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => { inputElement.value = response.data; protyle.scroll.element.setAttribute("aria-label", `Blocks ${response.data}/${protyle.block.blockCount}`); }); - }, Constants.TIMEOUT_BLOCKLOAD); + }, Constants.TIMEOUT_LOAD); } if (protyle.wysiwyg.element.getAttribute("data-top") || protyle.block.showAll || (protyle.scroll && protyle.scroll.element.classList.contains("fn__none")) || !protyle.scroll || diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index a2875b1b0..75b5be76a 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -988,7 +988,7 @@ export class Toolbar { } setTimeout(() => { addScript("stage/protyle/js/html2canvas.min.js?v=1.4.1", "protyleHtml2canvas").then(() => { - window.html2canvas(renderElement).then((canvas) => { + window.html2canvas(renderElement, {useCORS: true}).then((canvas) => { canvas.toBlob((blob: Blob) => { const formData = new FormData(); formData.append("file", blob); @@ -1000,7 +1000,7 @@ export class Toolbar { }); }); }); - }, Constants.TIMEOUT_TRANSITION); + }, Constants.TIMEOUT_LOAD); }; headerElement.addEventListener("mousedown", (event: MouseEvent) => { if (hasClosestByClassName(event.target as HTMLElement, "block__icon")) { diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts index ecb1f863a..f97588043 100644 --- a/app/src/protyle/ui/initUI.ts +++ b/app/src/protyle/ui/initUI.ts @@ -78,7 +78,7 @@ export const addLoading = (protyle: IProtyle) => { if (protyle.element.getAttribute("data-loading") !== "finished") { protyle.element.insertAdjacentHTML("beforeend", '