🎨 反链面板移除元素后,文档分屏且为空会重复添加空块

This commit is contained in:
Vanessa 2025-09-01 12:47:14 +08:00
parent e015f72945
commit 5c60e8d567

View file

@ -159,50 +159,7 @@ export class Protyle {
} }
break; break;
case "transactions": case "transactions":
data.data[0].doOperations.find((item: IOperation) => { this.onTransaction(data);
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();
}
}
}
});
break; break;
case "readonly": case "readonly":
window.siyuan.config.editor.readOnly = data.data; 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) { private getDoc(mergedOptions: IProtyleOptions) {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: mergedOptions.blockId, id: mergedOptions.blockId,