From c3269893918f6c147fe59fe7ce129e338d1ab524 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 6 Sep 2025 22:47:16 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/8019 --- app/src/protyle/util/insertHTML.ts | 54 ++++++++++++++++-------------- app/src/protyle/wysiwyg/remove.ts | 2 +- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts index f004ac63b..f907a1fbf 100644 --- a/app/src/protyle/util/insertHTML.ts +++ b/app/src/protyle/util/insertHTML.ts @@ -450,31 +450,29 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false, if (tempElement.content.firstChild.nodeType === 3 || (tempElement.content.firstChild.nodeType === 1 && tempElement.content.firstElementChild.tagName !== "DIV")) { tempElement.innerHTML = protyle.lute.SpinBlockDOM(tempElement.innerHTML); } - let foldHeadingId = ""; - let foldHTML = ""; + // let foldHeadingId = ""; + // let foldHTML = ""; // 粘贴内容中包含折叠的子节点需后端插入到原节点中 - Array.from(tempElement.content.children).forEach((item) => { - if (!item.getAttribute("parent-heading") && foldHeadingId && foldHTML) { - fetchPost("/api/block/appendHeadingChildren", {id: foldHeadingId, dom: foldHTML}); - foldHeadingId = ""; - foldHTML = ""; - } - if (item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") { - foldHeadingId = item.getAttribute("data-node-id"); - return true; - } - if (foldHeadingId && item.getAttribute("parent-heading")) { - foldHTML += item.outerHTML; - } - }); - if (foldHeadingId && foldHTML) { - fetchPost("/api/block/appendHeadingChildren", {id: foldHeadingId, dom: foldHTML}); - } + // Array.from(tempElement.content.children).forEach((item) => { + // if (!item.getAttribute("parent-heading") && foldHeadingId && foldHTML) { + // fetchPost("/api/block/appendHeadingChildren", {id: foldHeadingId, dom: foldHTML}); + // foldHeadingId = ""; + // foldHTML = ""; + // } + // if (item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") { + // foldHeadingId = item.getAttribute("data-node-id"); + // return true; + // } + // if (foldHeadingId && item.getAttribute("parent-heading")) { + // foldHTML += item.outerHTML; + // } + // }); + // if (foldHeadingId && foldHTML) { + // fetchPost("/api/block/appendHeadingChildren", {id: foldHeadingId, dom: foldHTML}); + // } (insertBefore ? Array.from(tempElement.content.children) : Array.from(tempElement.content.children).reverse()).find((item) => { - if (item.getAttribute("parent-heading")) { - return; - } let addId = item.getAttribute("data-node-id"); + const hasParentHeading = item.getAttribute("parent-heading"); if (addId === id) { doOperation.push({ action: "update", @@ -499,10 +497,12 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false, liElement.append(item); item = liElement; } + item.removeAttribute("parent-heading"); doOperation.push({ action: "insert", data: item.outerHTML, id: addId, + context: {ignoreProcess: hasParentHeading ? "true" : "false"}, nextID: insertBefore ? id : undefined, previousID: insertBefore ? undefined : id }); @@ -511,10 +511,12 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false, id: addId, }); } - if (insertBefore) { - blockElement.before(item); - } else { - blockElement.after(item); + if (!hasParentHeading) { + if (insertBefore) { + blockElement.before(item); + } else { + blockElement.after(item); + } } if (!lastElement) { lastElement = item; diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts index c4a91db52..7725a99e8 100644 --- a/app/src/protyle/wysiwyg/remove.ts +++ b/app/src/protyle/wysiwyg/remove.ts @@ -108,7 +108,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang } else { foldPreviousId = ""; } - // // https://github.com/siyuan-note/siyuan/issues/4422 + // https://github.com/siyuan-note/siyuan/issues/4422 topElement.firstElementChild.removeAttribute("contenteditable"); topElement.remove(); } else {