Vanessa 2025-09-14 12:38:40 +08:00
parent 327c3aaabb
commit f8d1d1958b
4 changed files with 46 additions and 8 deletions

View file

@ -150,7 +150,16 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id
if (blockElement.getAttribute("data-type") === "NodeListItem") {
newElement = genListItemElement(blockElement, 0, true) as HTMLDivElement;
orderIndex = parseInt(blockElement.parentElement.firstElementChild.getAttribute("data-marker"));
} else if (position === "beforebegin" && blockElement.previousElementSibling &&
blockElement.previousElementSibling.getAttribute("data-type") === "NodeHeading" &&
blockElement.previousElementSibling.getAttribute("fold") === "1") {
newElement = genHeadingElement(blockElement.previousElementSibling, false, true) as HTMLDivElement;
} else if (position === "afterend" && blockElement &&
blockElement.getAttribute("data-type") === "NodeHeading" &&
blockElement.getAttribute("fold") === "1") {
newElement = genHeadingElement(blockElement, false, true) as HTMLDivElement;
}
const parentOldHTML = blockElement.parentElement.outerHTML;
const newId = newElement.getAttribute("data-node-id");
blockElement.insertAdjacentElement(position, newElement);
@ -216,6 +225,17 @@ export const genEmptyElement = (zwsp = true, wbr = true, id?: string) => {
return element;
};
export const genHeadingElement = (headElement: Element, getHTML = false, addWbr = false) => {
const html = `<div data-subtype="${headElement.getAttribute("data-subtype")}" data-node-id="${Lute.NewNodeID()}" data-type="NodeHeading" class="${headElement.className}"><div contenteditable="true" spellcheck="false">${addWbr ? "<wbr>" : ""}</div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
if (getHTML) {
return html;
} else {
const tempElement = document.createElement("template");
tempElement.innerHTML = html;
return tempElement.content.firstElementChild;
}
};
export const getLangByType = (type: string) => {
let lang = type;
switch (type) {