This commit is contained in:
Vanessa 2025-10-22 19:32:46 +08:00
parent 8ce48f6135
commit 788a8d9a39

View file

@ -52,7 +52,12 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
let listElement: Element; let listElement: Element;
let topParentElement: Element; let topParentElement: Element;
hideElements(["select"], protyle); hideElements(["select"], protyle);
const unfoldOperations = []; const unfoldData: {
[key: string]: {
element: Element,
previousID: string
}
} = {};
for (let i = 0; i < selectElements.length; i++) { for (let i = 0; i < selectElements.length; i++) {
const item = selectElements[i]; const item = selectElements[i];
const topElement = getTopAloneElement(item); const topElement = getTopAloneElement(item);
@ -104,16 +109,22 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
data = protyle.lute.SpinBlockDOM(topElement.outerHTML); // 防止图表撤销问题 data = protyle.lute.SpinBlockDOM(topElement.outerHTML); // 防止图表撤销问题
} }
let previousID = topElement.previousElementSibling ? topElement.previousElementSibling.getAttribute("data-node-id") : ""; let previousID = topElement.previousElementSibling ? topElement.previousElementSibling.getAttribute("data-node-id") : "";
if (topElement.previousElementSibling && topElement.nextElementSibling && topElement.getAttribute("data-type") === "NodeHeading" && topElement.getAttribute("fold") !== "1" && if (topElement.previousElementSibling &&
topElement.previousElementSibling.getAttribute("data-type") === "NodeHeading" && topElement.previousElementSibling.getAttribute("fold") === "1" && topElement.previousElementSibling.getAttribute("data-type") === "NodeHeading" && topElement.previousElementSibling.getAttribute("fold") === "1" &&
(topElement.nextElementSibling.getAttribute("data-type") !== "NodeHeading" || (topElement.nextElementSibling?.getAttribute("data-type") !== "NodeHeading" ||
(topElement.nextElementSibling.getAttribute("data-type") === "NodeHeading" && topElement.nextElementSibling.getAttribute("data-subtype") < topElement.getAttribute("data-subtype")) (topElement.nextElementSibling?.getAttribute("data-type") === "NodeHeading" && topElement.nextElementSibling?.getAttribute("data-subtype") < topElement.getAttribute("data-subtype"))
)) { )) {
unfoldOperations.push(setFold(protyle, topElement.previousElementSibling, true, false, false, true)); const foldId = topElement.previousElementSibling.getAttribute("data-node-id");
const foldTransaction = await fetchSyncPost("/api/block/getHeadingDeleteTransaction", { if (!unfoldData[foldId]) {
id: topElement.previousElementSibling.getAttribute("data-node-id"), const foldTransaction = await fetchSyncPost("/api/block/getHeadingDeleteTransaction", {
}); id: foldId,
previousID = foldTransaction.data.doOperations[foldTransaction.data.doOperations.length - 1].id; });
unfoldData[foldId] = {
element: topElement.previousElementSibling,
previousID: foldTransaction.data.doOperations[foldTransaction.data.doOperations.length - 1].id
};
}
previousID = unfoldData[foldId].previousID;
} }
inserts.push({ inserts.push({
action: "insert", action: "insert",
@ -130,9 +141,10 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
topElement.remove(); topElement.remove();
} }
} }
unfoldOperations.forEach(item => { Object.keys(unfoldData).forEach(item => {
deletes.push(...item.doOperations); const foldOperations = setFold(protyle, unfoldData[item].element, true, false, false, true);
inserts.push(...item.undoOperations); deletes.push(...foldOperations.doOperations);
inserts.splice(0, 0, ...foldOperations.undoOperations);
}); });
if (sideElement) { if (sideElement) {
if (protyle.block.showAll && sideElement.classList.contains("protyle-wysiwyg") && protyle.wysiwyg.element.childElementCount === 0) { if (protyle.block.showAll && sideElement.classList.contains("protyle-wysiwyg") && protyle.wysiwyg.element.childElementCount === 0) {