Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: thub.com/siyuan-note/siyuan/issues/14496

Vanessa4d0c136a5600
diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts
index dc71ccedc3..3202559d3f 100644
--- a/app/src/protyle/index.ts
+++ b/app/src/protyle/index.ts
@@ -47,6 +47,7 @@ import {getAllModels} from "../layout/getAll";
/// #endif
import {isSupportCSSHL} from "./render/searchMarkRender";
import {renderAVAttribute} from "./render/av/blockAttr";
+import {genEmptyElement} from "../block/util";
export class Protyle {
@@ -175,6 +176,19 @@ export class Protyle {
return true;
} else {
onTransaction(this.protyle, item, false);
+ // 反链面板移除元素后,文档为空
+ if (this.protyle.wysiwyg.element.childElementCount === 0) {
+ 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;
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index fd020859aa..3c0c22ad90 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -19,6 +19,10 @@ import {Constants} from "../../constants";
import {scrollCenter} from "../../util/highlightById";
import {isMobile} from "../../util/functions";
import {mathRender} from "../render/mathRender";
+import {hasClosestByClassName} from "../util/hasClosest";
+import {getInstanceById} from "../../layout/util";
+import {Tab} from "../../layout/Tab";
+import {Backlink} from "../../layout/dock/Backlink";
export const removeBlock = async (protyle: IProtyle, blockElement: Element, range: Range, type: "Delete" | "Backspace" | "remove") => {
// 删除后,防止滚动条滚动后调用 get 请求,因为返回的请求已查找不到内容块了
@@ -69,7 +73,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
sideElement = getPreviousBlock(topElement);
}
}
- if (!sideElement) {
+ if (!sideElement && !protyle.options.backlinkData) {
sideElement = topElement.parentElement || protyle.wysiwyg.element.firstElementChild;
sideIsNext = false;
}
@@ -189,6 +193,24 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
}
hideElements(["util"], protyle);
+ if (!sideElement) {
+ const backlinkElement = hasClosestByClassName(protyle.element, "sy__backlink", true)
+ if (backlinkElement) {
+ const backLinkTab = getInstanceById(backlinkElement.getAttribute("data-id"));
+ if (backLinkTab instanceof Tab && backLinkTab.model instanceof Backlink) {
+ const editors = backLinkTab.model.editors
+ editors.find((item, index) => {
+ if (item.protyle.element.isSameNode(protyle.element)) {
+ item.destroy();
+ editors.splice(index, 1);
+ item.protyle.element.previousElementSibling.remove();
+ item.protyle.element.remove();
+ return true;
+ }
+ });
+ }
+ }
+ }
return;
}
const blockType = blockElement.getAttribute("data-type");
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index 7fadf2f189..12efee664b 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -123,7 +123,7 @@ const promiseTransaction = () => {
if (operation.action === "delete" || operation.action === "append") {
if (protyle.options.backlinkData) {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => {
- if (!isInEmbedBlock(item)) {
+ if (!isInEmbedBlock(item) && !item.contains(range.startContainer)) {
item.remove();
}
});
@@ -204,7 +204,7 @@ const promiseTransaction = () => {
});
} else {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.parentID}"]`)).forEach(item => {
- if (!isInEmbedBlock(item)) {
+ if (!isInEmbedBlock(item) && !item.contains(range.startContainer)) {
// 列表特殊处理
if (item.firstElementChild && item.firstElementChild.classList.contains("protyle-action") &&
item.firstElementChild.nextElementSibling.getAttribute("data-node-id") !== operation.id) {