From 85a76a59a538631b9e604c77920c4839b8058d7e Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 22 Oct 2025 17:18:39 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/16113 --- app/src/protyle/hint/index.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts index d2de82320..707ca04f0 100644 --- a/app/src/protyle/hint/index.ts +++ b/app/src/protyle/hint/index.ts @@ -16,7 +16,7 @@ import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "../ import {transaction, updateTransaction} from "../wysiwyg/transaction"; import {insertHTML} from "../util/insertHTML"; import {highlightRender} from "../render/highlightRender"; -import {assetMenu, imgMenu} from "../../menus/protyle"; +import {assetMenu, imgMenu, setFold} from "../../menus/protyle"; import {hideElements} from "../ui/hideElements"; import {fetchPost} from "../../util/fetch"; import {getDisplayName, pathPosix} from "../../util/pathName"; @@ -805,6 +805,14 @@ ${genHintItemHTML(item)} if (value === "
") { newHTML = `
${genIconHTML()}
${Constants.ZWSP}
`; } + const doOperations: IOperation[] = []; + const undoOperations: IOperation[] = []; + if (nodeElement.getAttribute("data-type") === "NodeHeading" && + nodeElement.getAttribute("fold") === "1") { + const foldData = setFold(protyle, nodeElement, true, false, false, true); + doOperations.push(...foldData.doOperations); + undoOperations.push(...foldData.undoOperations); + } nodeElement.insertAdjacentHTML("afterend", newHTML); const oldHTML = nodeElement.outerHTML; const newId = newHTML.substr(newHTML.indexOf('data-node-id="') + 14, 22); @@ -815,7 +823,7 @@ ${genHintItemHTML(item)} item.style.minWidth = "60px"; }); } - transaction(protyle, [{ + doOperations.push({ data: oldHTML, id, action: "update" @@ -824,14 +832,16 @@ ${genHintItemHTML(item)} id: newId, previousID: id, action: "insert" - }], [{ + }); + undoOperations.push({ id: newId, action: "delete" }, { data: html, id, action: "update" - }]); + }); + transaction(protyle, doOperations, undoOperations); } if (value === "
" || value === "$$" || (value.indexOf("```") > -1 && (value.length > 3 || nodeElement.classList.contains("render-node")))) { protyle.toolbar.showRender(protyle, nodeElement);