From 212c98d92a7642e9092b31806f538b93eedeee5d Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 20 May 2024 23:00:40 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/11475 --- app/src/protyle/wysiwyg/commonHotkey.ts | 40 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts index 8329ef64f..4ec052c77 100644 --- a/app/src/protyle/wysiwyg/commonHotkey.ts +++ b/app/src/protyle/wysiwyg/commonHotkey.ts @@ -186,9 +186,13 @@ export const getStartEndElement = (selectElements: NodeListOf | Element }; export const duplicateBlock = (nodeElements: Element[], protyle: IProtyle) => { - let focusElement; + let focusElement: Element; const doOperations: IOperation[] = []; const undoOperations: IOperation[] = []; + let starIndex: number; + if (nodeElements[nodeElements.length - 1].getAttribute("data-subtype") === "o") { + starIndex = parseInt(nodeElements[nodeElements.length - 1].getAttribute("data-marker"), 10); + } nodeElements.reverse().forEach((item, index) => { const tempElement = item.cloneNode(true) as HTMLElement; if (index === 0) { @@ -200,8 +204,13 @@ export const duplicateBlock = (nodeElements: Element[], protyle: IProtyle) => { childItem.setAttribute("data-node-id", Lute.NewNodeID()); }); item.classList.remove("protyle-wysiwyg--select"); - if (tempElement.dataset.type ==="NodeHTMLBlock") { - const phElement = tempElement.querySelector("protyle-html"); + if (typeof starIndex === "number") { + const orderIndex = starIndex + (nodeElements.length - index); + tempElement.setAttribute("data-marker", (orderIndex) + "."); + tempElement.querySelector(".protyle-action--order").textContent = (orderIndex) + "."; + } + if (tempElement.dataset.type === "NodeHTMLBlock") { + const phElement = tempElement.querySelector("protyle-html"); const content = phElement.getAttribute("data-content"); phElement.setAttribute("data-content", ""); nodeElements[0].after(tempElement); @@ -220,6 +229,31 @@ export const duplicateBlock = (nodeElements: Element[], protyle: IProtyle) => { id: newId, }); }); + if (typeof starIndex === "number") { + let nextElement = focusElement.nextElementSibling; + starIndex = starIndex + nodeElements.length; + while (nextElement) { + if (nextElement.getAttribute("data-subtype") === "o") { + starIndex++; + const id = nextElement.getAttribute("data-node-id"); + undoOperations.push({ + action: "update", + id, + data: nextElement.outerHTML, + }); + nextElement.setAttribute("data-marker", starIndex + "."); + nextElement.querySelector(".protyle-action--order").textContent = starIndex + "."; + doOperations.push({ + action: "update", + data: nextElement.outerHTML, + id, + }); + nextElement = nextElement.nextElementSibling; + } else { + break; + } + } + } transaction(protyle, doOperations, undoOperations); focusBlock(focusElement); scrollCenter(protyle);