An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Correct heading folding state handling https://github.com/siyuan-note/siyuan/issues/18218
Daniel0c800302562e
diff --git a/app/src/protyle/util/blockFold.ts b/app/src/protyle/util/blockFold.tsindex a3aa31817c..93f5e0396c 100644--- a/app/src/protyle/util/blockFold.ts+++ b/app/src/protyle/util/blockFold.ts@@ -172,18 +172,19 @@ const foldBlocksRecursively0 = async (protyle: IProtyle, nodeElements: Element[]return;}- // Determine target state: if any block is unfolded, we fold all. Otherwise we expand all.+ // 任一候选块未折叠时执行全部折叠;全部已折叠时执行全部展开。let isFoldAll = elementsToFold.some(item => item.getAttribute("fold") !== "1");+ // 单个入口已折叠时以展开入口为准,后代状态不影响操作方向。if (isFoldAll && nodeElements.length === 1 && nodeElements[0].getAttribute("fold") === "1") {isFoldAll = false;}- if (isFoldAll) {- elementsToFold.reverse();- }+ // 内层状态需要先写入内核,外层标题最后展开时返回的 DOM 才能包含后代块的最终折叠状态。+ const elementsToProcess = Array.from(elementsToFold).reverse();+ const scrollElement = (isFoldAll ? elementsToProcess : elementsToFold).find(element => element.isConnected);const doOperations: IOperation[] = [];const undoOperations: IOperation[] = [];- elementsToFold.forEach(element => {+ elementsToProcess.forEach(element => {const hasFold = element.getAttribute("fold") === "1";if ((isFoldAll && hasFold) || (!isFoldAll && !hasFold)) {return;@@ -218,7 +219,6 @@ const foldBlocksRecursively0 = async (protyle: IProtyle, nodeElements: Element[]if (doOperations.length > 0) {transaction(protyle, doOperations, undoOperations);preventScroll(protyle);- const scrollElement = elementsToFold.find((element) => element.isConnected);if (scrollElement) {scrollCenter(protyle, scrollElement);}diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex be1f3b6531..2cbea59c6a 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -33,6 +33,9 @@ const removePlaceholderRows = (blockElement: HTMLElement) => {};const markFoldHeadingChildren = (parent: ParentNode) => {+ parent.querySelectorAll("[parent-heading]").forEach(item => {+ item.removeAttribute("parent-heading");+ });const foldedHeadings: {id: string, level: number}[] = [];Array.from(parent.children).forEach(item => {if (!item.hasAttribute("data-node-id")) {@@ -702,6 +705,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,(insertBefore ? Array.from(tempElement.content.children) : Array.from(tempElement.content.children).reverse()).find((item) => {let addId = item.getAttribute("data-node-id");const hasParentHeading = item.getAttribute("parent-heading");+ item.removeAttribute("parent-heading");if (addId === id) {item.setAttribute(Constants.ATTRIBUTE_EDITING, "true");doOperation.push({@@ -727,7 +731,6 @@ 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,