Vanessa 2025-09-06 22:47:16 +08:00
parent 468b670bcc
commit c326989391
2 changed files with 29 additions and 27 deletions

View file

@ -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;

View file

@ -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 {