diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index b827cefb4..bd781c455 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -1935,7 +1935,7 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
const id = nodeElement.getAttribute("data-node-id");
if (nodeElement.getAttribute("data-type") === "NodeHeading") {
if (hasFold) {
- nodeElement.insertAdjacentHTML("beforeend", '
');
+ nodeElement.insertAdjacentHTML("beforeend", '');
transaction(protyle, [{
action: "unfoldHeading",
id,
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index 5f1df1c27..d95b3a3db 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -45,6 +45,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
let listElement: Element;
let topParentElement: Element;
hideElements(["select"], protyle);
+ let foldPreviousId: string
selectElements.find((item: HTMLElement) => {
const topElement = getTopAloneElement(item);
topParentElement = topElement.parentElement;
@@ -74,13 +75,27 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
if (topElement.getAttribute("data-type") === "NodeHeading" && topElement.getAttribute("fold") === "1") {
// https://github.com/siyuan-note/siyuan/issues/2188
setFold(protyle, topElement, undefined, true);
+ let previousID = topElement.previousElementSibling ? topElement.previousElementSibling.getAttribute("data-node-id") : ""
+ if (typeof foldPreviousId !== "undefined") {
+ previousID = foldPreviousId;
+ }
inserts.push({
action: "insert",
data: topElement.outerHTML,
id,
- previousID: selectElements[0].previousElementSibling ? selectElements[0].previousElementSibling.getAttribute("data-node-id") : "",
+ previousID: previousID,
parentID: topElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID
});
+ // 折叠块和非折叠块同时删除时撤销异常 https://github.com/siyuan-note/siyuan/issues/11312
+ let foldPreviousElement = getPreviousBlock(topElement);
+ while (foldPreviousElement && foldPreviousElement.childElementCount === 3) {
+ foldPreviousElement = getPreviousBlock(foldPreviousElement);
+ }
+ if (foldPreviousElement) {
+ foldPreviousId = foldPreviousElement.getAttribute("data-node-id");
+ } else {
+ foldPreviousId = "";
+ }
// https://github.com/siyuan-note/siyuan/issues/4422
topElement.firstElementChild.removeAttribute("contenteditable");
// 在折叠标题后输入文字,然后全选删除再撤销会重建索引。因此不能删除折叠标题后新输入的输入折叠标题下的内容
@@ -97,11 +112,15 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
if (topElement.classList.contains("render-node") || topElement.querySelector("div.render-node")) {
data = protyle.lute.SpinBlockDOM(topElement.outerHTML); // 防止图表撤销问题
}
+ let previousID = topElement.previousElementSibling ? topElement.previousElementSibling.getAttribute("data-node-id") : "";
+ if (typeof foldPreviousId !== "undefined") {
+ previousID = foldPreviousId;
+ }
inserts.push({
action: "insert",
data,
id,
- previousID: topElement.previousElementSibling ? topElement.previousElementSibling.getAttribute("data-node-id") : "",
+ previousID,
parentID: topElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID
});
if (topElement.getAttribute("data-subtype") === "o" && topElement.classList.contains("li")) {
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index c181951eb..c6b92520d 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -297,6 +297,21 @@ const promiseTransaction = () => {
updateRef(protyle, operation.id);
}
});
+
+ // 删除仅有的折叠标题后展开内容为空
+ if (protyle.wysiwyg.element.childElementCount === 0) {
+ 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);
+ }
});
};