Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/17800

Vanessa6957d04b420f
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index 41379a6a40..6b6149668d 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -215,6 +215,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
id: listElement.getAttribute("data-node-id"),
data: listElement.outerHTML
});
+ listElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true");
updateListOrder(listElement, 1);
deletes.push({
action: "update",
@@ -428,7 +429,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
const parentElement = hasClosestBlock(getParentBlock(blockElement));
const editableElement = getContenteditableElement(blockElement);
- const previousLastElement = getLastBlock(previousElement) as HTMLElement;
+ let previousLastElement = getLastBlock(previousElement) as HTMLElement;
if (range.toString() === "" && isMobile() && previousLastElement && previousLastElement.classList.contains("hr") && getSelectionOffset(editableElement).start === 0) {
transaction(protyle, [{
action: "delete",
@@ -564,7 +565,9 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
}
}
// 图片前删除到上一个文字块时,图片前有 zwsp
- previousLastElement.outerHTML = protyle.lute.SpinBlockDOM(previousLastElement.outerHTML);
+ previousLastElement.insertAdjacentHTML("afterend", protyle.lute.SpinBlockDOM(previousLastElement.outerHTML));
+ previousLastElement = previousLastElement.nextElementSibling as HTMLElement;
+ previousLastElement.previousElementSibling.remove();
mathRender(getPreviousBlock(removeElement) as HTMLElement);
const removeParentElement = removeElement.parentElement;
// https://github.com/siyuan-note/siyuan/issues/12327
@@ -706,6 +709,7 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDele
if (listElement.getAttribute("data-subtype") === "o") {
updateListOrder(listElement, parseInt(listElement.firstElementChild.getAttribute("data-marker")) - 1);
}
+ listElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true");
doOperations.splice(0, 0, {
action: "update",
id: listElement.getAttribute("data-node-id"),
@@ -836,6 +840,7 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDele
id: nextId,
data: nextElement.outerHTML
});
+ nextElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true");
nextElement = nextElement.nextElementSibling;
}
}
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index e9f5376515..2f0c2024c7 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -269,6 +269,22 @@ const promiseTransaction = (options: {
});
}
});
+ // 删除仅有的折叠标题后展开内容为空
+ if (protyle.wysiwyg.element.childElementCount === 0 &&
+ // 聚焦时不需要新增块,否则会导致 https://github.com/siyuan-note/siyuan/issues/12326 第一点
+ !protyle.block.showAll) {
+ const newID = Lute.NewNodeID();
+ const emptyElement = genEmptyElement(false, true, newID);
+ protyle.wysiwyg.element.insertAdjacentElement("afterbegin", emptyElement);
+ transaction(protyle, [{
+ action: "insert",
+ data: emptyElement.outerHTML,
+ id: newID,
+ parentID: protyle.block.parentID
+ }]);
+ // 不能撤销,否则就无限循环了
+ focusByWbr(emptyElement, range);
+ }
}
fetchPost("/api/transactions", {
session: protyle.id,
@@ -291,22 +307,6 @@ const promiseTransaction = (options: {
}
});
}
- // 删除仅有的折叠标题后展开内容为空
- if (protyle.wysiwyg.element.childElementCount === 0 &&
- // 聚焦时不需要新增块,否则会导致 https://github.com/siyuan-note/siyuan/issues/12326 第一点
- !protyle.block.showAll) {
- const newID = Lute.NewNodeID();
- const emptyElement = genEmptyElement(false, true, newID);
- protyle.wysiwyg.element.insertAdjacentElement("afterbegin", emptyElement);
- transaction(protyle, [{
- action: "insert",
- data: emptyElement.outerHTML,
- id: newID,
- parentID: protyle.block.parentID
- }]);
- // 不能撤销,否则就无限循环了
- focusByWbr(emptyElement, range);
- }
});
};