From 5c60e8d5673e297f973cf24e9bcd79de199cd73b Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 1 Sep 2025 12:47:14 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=8F=8D=E9=93=BE=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=85=83=E7=B4=A0=E5=90=8E=EF=BC=8C=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E5=88=86=E5=B1=8F=E4=B8=94=E4=B8=BA=E7=A9=BA=E4=BC=9A?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=B7=BB=E5=8A=A0=E7=A9=BA=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/protyle/index.ts | 88 ++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index c0bcbef03..33b6518a8 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -159,50 +159,7 @@ export class Protyle { } break; case "transactions": - data.data[0].doOperations.find((item: IOperation) => { - if (!this.protyle.preview.element.classList.contains("fn__none")) { - this.protyle.preview.render(this.protyle); - } else if (options.backlinkData && ["delete", "move"].includes(item.action)) { - // 只对特定情况刷新,否则展开、编辑等操作刷新会频繁 - /// #if !MOBILE - getAllModels().backlink.find(backlinkItem => { - if (backlinkItem.element.contains(this.protyle.element)) { - backlinkItem.refresh(); - return true; - } - }); - /// #endif - return true; - } else { - onTransaction(this.protyle, item, false); - // 反链面板移除元素后,文档为空 - if (this.protyle.wysiwyg.element.childElementCount === 0 && this.protyle.block.parentID && - !(item.action === "delete" && typeof item.data?.createEmptyParagraph === "boolean" && !item.data.createEmptyParagraph)) { - if (item.action === "delete" && this.protyle.block.showAll) { - if (this.protyle.options.handleEmptyContent) { - this.protyle.options.handleEmptyContent(); - } else { - zoomOut({ - protyle: this.protyle, - id: this.protyle.block.rootID, - focusId: this.protyle.block.id - }); - } - } else { - const newID = Lute.NewNodeID(); - const emptyElement = genEmptyElement(false, false, newID); - this.protyle.wysiwyg.element.append(emptyElement); - transaction(this.protyle, [{ - action: "insert", - data: emptyElement.outerHTML, - id: newID, - parentID: this.protyle.block.parentID - }]); - this.protyle.undo.clear(); - } - } - } - }); + this.onTransaction(data); break; case "readonly": window.siyuan.config.editor.readOnly = data.data; @@ -329,6 +286,49 @@ export class Protyle { } } + private onTransaction(data: IWebSocketData) { + let needCreateAction = ""; + data.data[0].doOperations.find((item: IOperation) => { + if (!this.protyle.preview.element.classList.contains("fn__none")) { + this.protyle.preview.render(this.protyle); + } else if (this.protyle.options.backlinkData && ["delete", "move"].includes(item.action)) { + // 只对特定情况刷新,否则展开、编辑等操作刷新会频繁 + /// #if !MOBILE + getAllModels().backlink.find(backlinkItem => { + if (backlinkItem.element.contains(this.protyle.element)) { + backlinkItem.refresh(); + return true; + } + }); + /// #endif + return true; + } else { + onTransaction(this.protyle, item, false); + // 反链面板移除元素后,文档为空 + if (!(item.action === "delete" && typeof item.data?.createEmptyParagraph === "boolean" && !item.data.createEmptyParagraph)) { + needCreateAction = item.action; + } + } + }); + if (this.protyle.wysiwyg.element.childElementCount === 0 && this.protyle.block.parentID && needCreateAction) { + if (needCreateAction === "delete" && this.protyle.block.showAll) { + if (this.protyle.options.handleEmptyContent) { + this.protyle.options.handleEmptyContent(); + } else { + zoomOut({ + protyle: this.protyle, + id: this.protyle.block.rootID, + focusId: this.protyle.block.id + }); + } + } else { + // 不能使用 transaction,否则分屏后会重复添加 + this.protyle.undo.clear(); + this.reload(false); + } + } + } + private getDoc(mergedOptions: IProtyleOptions) { fetchPost("/api/filetree/getDoc", { id: mergedOptions.blockId,