An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/9521
Vanessa9bea5eda1b0a
diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scssindex 25caf6b95e..c1870fb19b 100644--- a/app/src/assets/scss/protyle/_wysiwyg.scss+++ b/app/src/assets/scss/protyle/_wysiwyg.scss@@ -291,7 +291,6 @@}}- // 超级块内拖拽调整子块宽度的手柄 https://github.com/siyuan-note/siyuan/issues/9521> .sb__resize {align-self: stretch;width: 4px;diff --git a/app/src/block/util.ts b/app/src/block/util.tsindex e6f192d096..e3f26ea3bd 100644--- a/app/src/block/util.ts+++ b/app/src/block/util.ts@@ -40,6 +40,8 @@ export const cancelSB = async (protyle: IProtyle, nodeElement: Element, range?:previousID: previousId,parentID,});+ // 移出子块前先清理拖拽手柄,避免手柄(无 data-node-id)被遍历成 id 为空的 move 操作+ nodeElement.querySelectorAll(".sb__resize").forEach(handle => handle.remove());Array.from(nodeElement.children).forEach((item, index) => {if (index === nodeElement.childElementCount - 1) {doOperations.push({@@ -50,8 +52,6 @@ export const cancelSB = async (protyle: IProtyle, nodeElement: Element, range?:getContenteditableElement(nodeElement).insertAdjacentHTML("afterbegin", "<wbr>");}nodeElement.lastElementChild.remove();- // 清理残留的拖拽手柄,避免被当作兄弟块移出 https://github.com/siyuan-note/siyuan/issues/9521- nodeElement.querySelectorAll(".sb__resize").forEach(handle => handle.remove());nodeElement.replaceWith(...nodeElement.children);if (range) {focusByWbr(protyle.wysiwyg.element, range);@@ -96,14 +96,7 @@ export const genSBElement = (layout: string, id?: string, attrHTML?: string) =>return sbElement;};-// 统计超级块内的真实子块数量(排除 sb__resize 手柄、protyle-attr 等装饰元素)-// https://github.com/siyuan-note/siyuan/issues/9521-export const getSbChildCount = (sbElement: Element) =>- sbElement.querySelectorAll(":scope > [data-node-id]").length;-// 刷新超级块横向布局下的拖拽手柄:col 布局在每两个相邻子块间插入 sb__resize,非 col 移除全部-// 手柄是纯装饰元素,回流时由 lute 的 genASTByBlockDOM 按 sb__resize class 忽略,不产生幽灵块-// https://github.com/siyuan-note/siyuan/issues/9521export const refreshSbResize = (sbElement: Element) => {if (!sbElement || !sbElement.classList.contains("sb")) {return;diff --git a/app/src/protyle/util/blockFold.ts b/app/src/protyle/util/blockFold.tsindex 840c11df7e..6b6e1085b5 100644--- a/app/src/protyle/util/blockFold.ts+++ b/app/src/protyle/util/blockFold.ts@@ -6,8 +6,7 @@ import {focusBlock} from "./selection";import {scrollCenter} from "../../util/highlightById";import {clearSelect} from "./clear";import {removeFoldHeading} from "./heading";-import {getTopAloneElement} from "../wysiwyg/getBlock";-import {getSbChildCount} from "../../block/util";+import {getSbChildBlockCount, getTopAloneElement} from "../wysiwyg/getBlock";export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolean,isRemove?: boolean, addLoading = true, getOperations = false) => {@@ -100,7 +99,7 @@ const isFoldable = (el: Element) => {return type === "NodeHeading" ||(type === "NodeCallout" && el.querySelector(".callout-content").childElementCount > 1) ||((type === "NodeListItem" || type === "NodeBlockquote") && el.childElementCount > 3) ||- (type === "NodeSuperBlock" && getSbChildCount(el) > 1);+ (type === "NodeSuperBlock" && getSbChildBlockCount(el) > 1);};export const foldBlocksRecursively = (protyle: IProtyle, nodeElements: Element[]) => {diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex 7efd085514..1d3d4110d5 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -9,9 +9,9 @@ import {} from "./hasClosest";import {Constants} from "../../constants";import {paste} from "./paste";-import {cancelSB, genEmptyElement, genSBElement, getSbChildCount, insertEmptyBlock, refreshSbResize} from "../../block/util";+import {cancelSB, genEmptyElement, genSBElement, insertEmptyBlock, refreshSbResize} from "../../block/util";import {transaction, turnsIntoOneTransaction} from "../wysiwyg/transaction";-import {getParentBlock, getTopAloneElement} from "../wysiwyg/getBlock";+import {getParentBlock, getSbChildBlockCount, getTopAloneElement} from "../wysiwyg/getBlock";import {updateListOrder} from "../wysiwyg/list";import {fetchPost, fetchSyncPost} from "../../util/fetch";import {onGet} from "./onGet";@@ -217,7 +217,7 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElemensameElement.remove();}}- if (topSourceParentElement.classList.contains("sb") && getSbChildCount(topSourceParentElement) === 1) {+ if (topSourceParentElement.classList.contains("sb") && getSbChildBlockCount(topSourceParentElement) === 1) {// 拖拽后,sb 只剩下一个元素if (isSameDoc) {const sbData = await cancelSB(protyle, topSourceParentElement);@@ -238,7 +238,7 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElemen/// #endif}}- } else if (oldSourceParentElement.classList.contains("sb") && getSbChildCount(oldSourceParentElement) === 1) {+ } else if (oldSourceParentElement.classList.contains("sb") && getSbChildBlockCount(oldSourceParentElement) === 1) {// 拖拽后,sb 只剩下一个元素if (isSameDoc) {const sbData = await cancelSB(protyle, oldSourceParentElement);@@ -463,7 +463,6 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemendoOperations.push(...foldOperations.doOperations);undoOperations.splice(0, 0, ...foldOperations.undoOperations);});- // 子块移入完成后刷新拖拽手柄 https://github.com/siyuan-note/siyuan/issues/9521refreshSbResize(sbElement);if (isSameDoc || isCopy) {transaction(protyle, doOperations, undoOperations);@@ -544,6 +543,15 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElemreturn true;}});+ // 移入/移出超级块后刷新拖拽手柄(如 A 拖到超级块内 B 前面,需在 A、B 间补手柄)+ const dragSbSet = new Set<Element>();+ [newSourceParentElement[0], targetElement].forEach(el => {+ const sb = el?.closest('[data-type="NodeSuperBlock"]');+ if (sb) {+ dragSbSet.add(sb);+ }+ });+ dragSbSet.forEach(sb => refreshSbResize(sb));if (isSameDoc || isCopy) {transaction(protyle, doOperations, undoOperations);} else {diff --git a/app/src/protyle/wysiwyg/getBlock.ts b/app/src/protyle/wysiwyg/getBlock.tsindex 244ea1d5e4..4a6d02e103 100644--- a/app/src/protyle/wysiwyg/getBlock.ts+++ b/app/src/protyle/wysiwyg/getBlock.ts@@ -1,6 +1,5 @@import {hasClosestBlock, isInEmbedBlock} from "../util/hasClosest";import {Constants} from "../../constants";-import {getSbChildCount} from "../../block/util";export const getParentBlock = (element: Element) => {if (element.parentElement.classList.contains("callout-content") ||@@ -18,8 +17,12 @@ export const getCalloutInfo = (element: Element) => {export const getPreviousBlock = (element: Element) => {let parentElement = element;while (parentElement) {- if (parentElement.previousElementSibling && parentElement.previousElementSibling.getAttribute("data-node-id")) {- return parentElement.previousElementSibling;+ let previous = parentElement.previousElementSibling;+ while (previous && !previous.getAttribute("data-node-id")) {+ previous = previous.previousElementSibling;+ }+ if (previous) {+ return previous;}const pElement = hasClosestBlock(parentElement.parentElement);if (pElement) {@@ -30,6 +33,17 @@ export const getPreviousBlock = (element: Element) => {}};+export const getSbChildBlockCount = (sbElement: Element) =>+ sbElement.querySelectorAll(":scope > [data-node-id]").length;++export const getPreviousBlockSibling = (element: Element): Element => {+ let previous = element.previousElementSibling;+ while (previous && !previous.getAttribute("data-node-id")) {+ previous = previous.previousElementSibling;+ }+ return previous;+};+export const getLastBlock = (element: Element) => {let lastElement;Array.from(element.querySelectorAll("[data-node-id]")).reverse().find(item => {@@ -55,8 +69,12 @@ export const getFirstBlock = (element: Element) => {export const getNextBlock = (element: Element) => {let parentElement = element;while (parentElement) {- if (parentElement.nextElementSibling && !parentElement.nextElementSibling.classList.contains("protyle-attr")) {- return parentElement.nextElementSibling as HTMLElement;+ let next = parentElement.nextElementSibling;+ while (next && !next.getAttribute("data-node-id")) {+ next = next.nextElementSibling;+ }+ if (next) {+ return next as HTMLElement;}const pElement = hasClosestBlock(parentElement.parentElement);if (pElement) {@@ -181,9 +199,9 @@ export const getTopAloneElement = (topSourceElement: Element) => {break;}}- } else if ("NodeSuperBlock" === topSourceElement.parentElement.getAttribute("data-type") && getSbChildCount(topSourceElement.parentElement) === 1) {+ } else if ("NodeSuperBlock" === topSourceElement.parentElement.getAttribute("data-type") && getSbChildBlockCount(topSourceElement.parentElement) === 1) {while (topSourceElement.parentElement && !topSourceElement.parentElement.classList.contains("protyle-wysiwyg")) {- if (topSourceElement.parentElement.getAttribute("data-type") === "NodeSuperBlock" && getSbChildCount(topSourceElement.parentElement) === 1) {+ if (topSourceElement.parentElement.getAttribute("data-type") === "NodeSuperBlock" && getSbChildBlockCount(topSourceElement.parentElement) === 1) {topSourceElement = topSourceElement.parentElement;} else {topSourceElement = getTopAloneElement(topSourceElement);diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex ed186611fb..8e9c5ca89d 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -664,7 +664,9 @@ export class WYSIWYG {hasJump = true;}} else {- selectElements.push(currentElement);+ if (!currentElement.classList.contains("sb__resize")) {+ selectElements.push(currentElement);+ }currentElement = currentElement.nextElementSibling as HTMLElement;}} else if (currentElement.parentElement.classList.contains("sb")) {@@ -1424,7 +1426,8 @@ export class WYSIWYG {}} else {if (!currentElement.classList.contains("protyle-breadcrumb__bar") &&- !currentElement.classList.contains("protyle-breadcrumb__item")) {+ !currentElement.classList.contains("protyle-breadcrumb__item") &&+ !currentElement.classList.contains("sb__resize")) {selectElements.push(currentElement);}if (!currentElement.nextElementSibling && currentElement.parentElement.classList.contains("callout-content")) {diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.tsindex 73db1709d9..e8a12e93a4 100644--- a/app/src/protyle/wysiwyg/remove.ts+++ b/app/src/protyle/wysiwyg/remove.ts@@ -9,14 +9,14 @@ import {getContenteditableElement,getLastBlock,getNextBlock, getParentBlock,- getPreviousBlock,+ getPreviousBlock, getPreviousBlockSibling, getSbChildBlockCount,getTopAloneElement,getTopEmptyElement,hasNextSibling,hasPreviousSibling} from "./getBlock";import {transaction, turnsIntoOneTransaction, turnsIntoTransaction, updateTransaction} from "./transaction";-import {cancelSB, genEmptyElement, getSbChildCount} from "../../block/util";+import {cancelSB, genEmptyElement, refreshSbResize} from "../../block/util";import {listOutdent, updateListOrder} from "./list";import {zoomOut} from "../../menus/protyle";import {preventScroll} from "../scroll/preventScroll";@@ -109,16 +109,17 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang}});foldTransaction.data.undoOperations.reverse();- if (topElement.previousElementSibling &&- topElement.previousElementSibling.getAttribute("data-type") === "NodeHeading" &&- topElement.previousElementSibling.getAttribute("fold") === "1") {- const foldId = topElement.previousElementSibling.getAttribute("data-node-id");+ const foldPreviousBlockElement = getPreviousBlockSibling(topElement);+ if (foldPreviousBlockElement &&+ foldPreviousBlockElement.getAttribute("data-type") === "NodeHeading" &&+ foldPreviousBlockElement.getAttribute("fold") === "1") {+ const foldId = foldPreviousBlockElement.getAttribute("data-node-id");if (!unfoldData[foldId]) {const foldTransaction = await fetchSyncPost("/api/block/getHeadingDeleteTransaction", {id: foldId,});unfoldData[foldId] = {- element: topElement.previousElementSibling,+ element: foldPreviousBlockElement,previousID: foldTransaction.data.doOperations[foldTransaction.data.doOperations.length - 1].id};}@@ -132,17 +133,18 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rangif (topElement.classList.contains("render-node") || topElement.querySelector("div.render-node")) {data = protyle.lute.SpinBlockDOM(topElement.outerHTML); // 防止图表撤销问题}- let previousID = topElement.previousElementSibling ? topElement.previousElementSibling.getAttribute("data-node-id") : "";- if (topElement.previousElementSibling &&- topElement.previousElementSibling.getAttribute("data-type") === "NodeHeading" &&- topElement.previousElementSibling.getAttribute("fold") === "1") {- const foldId = topElement.previousElementSibling.getAttribute("data-node-id");+ const previousBlockElement = getPreviousBlockSibling(topElement);+ let previousID = previousBlockElement ? previousBlockElement.getAttribute("data-node-id") : "";+ if (previousBlockElement &&+ previousBlockElement.getAttribute("data-type") === "NodeHeading" &&+ previousBlockElement.getAttribute("fold") === "1") {+ const foldId = previousBlockElement.getAttribute("data-node-id");if (!unfoldData[foldId]) {const foldTransaction = await fetchSyncPost("/api/block/getHeadingDeleteTransaction", {id: foldId,});unfoldData[foldId] = {- element: topElement.previousElementSibling,+ element: previousBlockElement,previousID: foldTransaction.data.doOperations[foldTransaction.data.doOperations.length - 1].id};}@@ -226,10 +228,14 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang}}if (deletes.length > 0) {- if (topParentElement && topParentElement.getAttribute("data-type") === "NodeSuperBlock" && getSbChildCount(topParentElement) === 1) {+ if (topParentElement && topParentElement.getAttribute("data-type") === "NodeSuperBlock" && getSbChildBlockCount(topParentElement) === 1) {const sbData = await cancelSB(protyle, topParentElement, range);transaction(protyle, deletes.concat(sbData.doOperations), sbData.undoOperations.concat(inserts.reverse()));} else {+ // 超级块删除子块后剩余多个子块时,刷新拖拽手柄(被删块两侧手柄需移除/重建)+ if (topParentElement && topParentElement.getAttribute("data-type") === "NodeSuperBlock") {+ refreshSbResize(topParentElement);+ }transaction(protyle, deletes, inserts.reverse());}}@@ -438,7 +444,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rangaction: "insert",data: previousLastElement.outerHTML,id: previousLastElement.getAttribute("data-node-id"),- previousID: previousLastElement.previousElementSibling?.getAttribute("data-node-id"),+ previousID: getPreviousBlockSibling(previousLastElement)?.getAttribute("data-node-id"),parentID: getParentBlock(previousLastElement).getAttribute("data-node-id")}]);previousLastElement.remove();@@ -464,12 +470,12 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rangaction: "insert",data: blockElement.outerHTML,id: id,- previousID: blockElement.previousElementSibling?.getAttribute("data-node-id"),+ previousID: getPreviousBlockSibling(blockElement)?.getAttribute("data-node-id"),parentID: getParentBlock(blockElement).getAttribute("data-node-id")}];blockElement.remove();// 取消超级块- if (parentElement && parentElement.getAttribute("data-type") === "NodeSuperBlock" && getSbChildCount(parentElement) === 1) {+ if (parentElement && parentElement.getAttribute("data-type") === "NodeSuperBlock" && getSbChildBlockCount(parentElement) === 1) {const sbData = await cancelSB(protyle, parentElement);transaction(protyle, doOperations.concat(sbData.doOperations), sbData.undoOperations.concat(undoOperations));} else {@@ -500,8 +506,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rangaction: "insert",data: removeElement.outerHTML,id: removeId,- // 不能使用 previousLastElement,否则在超级块下的元素前删除撤销错误- previousID: blockElement.previousElementSibling?.getAttribute("data-node-id"),+ previousID: getPreviousBlockSibling(blockElement)?.getAttribute("data-node-id"),parentID: parentElement ? parentElement.getAttribute("data-node-id") : protyle.block.parentID}];const doOperations: IOperation[] = [{@@ -588,10 +593,13 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rangid: previousId,});}- if (parentElement && parentElement.getAttribute("data-type") === "NodeSuperBlock" && getSbChildCount(parentElement) === 1) {+ if (parentElement && parentElement.getAttribute("data-type") === "NodeSuperBlock" && getSbChildBlockCount(parentElement) === 1) {const sbData = await cancelSB(protyle, parentElement);transaction(protyle, doOperations.concat(sbData.doOperations), sbData.undoOperations.concat(undoOperations));} else {+ if (parentElement && parentElement.getAttribute("data-type") === "NodeSuperBlock") {+ refreshSbResize(parentElement);+ }transaction(protyle, doOperations, undoOperations);}focusByWbr(protyle.wysiwyg.element, range);diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex 88c1cc073b..c85e45dec0 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -1,6 +1,6 @@import {fetchPost, fetchSyncPost} from "../../util/fetch";import {focusBlock, focusByWbr, focusSideBlock, getEditorRange} from "../util/selection";-import {getContenteditableElement, getFirstBlock, getTopAloneElement} from "./getBlock";+import {getContenteditableElement, getFirstBlock, getSbChildBlockCount, getTopAloneElement} from "./getBlock";import {Constants} from "../../constants";import {blockRender} from "../render/blockRender";import {processRender} from "../util/processCode";@@ -13,7 +13,7 @@ import {getAllModels} from "../../layout/getAll";/// #endifimport {avRender, refreshAV} from "../render/av/render";import {removeFoldHeading} from "../util/heading";-import {cancelSB, genEmptyElement, genSBElement, getSbChildCount, refreshSbResize} from "../../block/util";+import {cancelSB, genEmptyElement, genSBElement, refreshSbResize} from "../../block/util";import {hideElements} from "../ui/hideElements";import {reloadProtyle} from "../util/reload";import {countBlockWord} from "../../layout/status";@@ -200,6 +200,16 @@ const promiseTransaction = (options: {blockRender(protyle, item);}});+ // 移动块(含撤销移动)后刷新相关超级块的拖拽手柄,避免手柄残留/缺失+ [operation.id, operation.parentID, operation.previousID].forEach(blockId => {+ if (blockId) {+ const el = protyle.wysiwyg.element.querySelector(`[data-node-id="${blockId}"]`);+ const sbAncestor = el?.closest('[data-type="NodeSuperBlock"]');+ if (sbAncestor) {+ refreshSbResize(sbAncestor);+ }+ }+ });return;}if (operation.action === "insert") {@@ -249,10 +259,22 @@ const promiseTransaction = (options: {item.querySelectorAll("wbr").forEach(wbrItem => {wbrItem.remove();});+ // 插入块后刷新所在超级块的拖拽手柄 https://github.com/siyuan-note/siyuan/issues/9521+ const sbAncestor = item.closest('[data-type="NodeSuperBlock"]');+ if (sbAncestor) {+ refreshSbResize(sbAncestor);+ }});protyle.wysiwyg.element.querySelectorAll("[parent-heading]").forEach(item => {item.remove();});+ // 兜底:本地发起的 insert 新块已在 DOM(跳过插入),但父超级块手柄仍需刷新+ // https://github.com/siyuan-note/siyuan/issues/9521+ const insertedEl = protyle.wysiwyg.element.querySelector(`[data-node-id="${operation.id}"]`);+ const insertedSb = insertedEl?.closest('[data-type="NodeSuperBlock"]');+ if (insertedSb) {+ refreshSbResize(insertedSb);+ }return;}if (operation.action === "setAttrs") {@@ -314,7 +336,13 @@ const deleteBlock = (updateElements: Element[], id: string, protyle: IProtyle, iif (isUndo && updateElements[0]) {focusSideBlock(updateElements[0]);}+ // 删除前记录所在超级块,删除后刷新其拖拽手柄 https://github.com/siyuan-note/siyuan/issues/9521+ const sbParents: Element[] = [];updateElements.forEach(item => {+ const sbAncestor = item.closest('[data-type="NodeSuperBlock"]');+ if (sbAncestor && !sbParents.includes(sbAncestor)) {+ sbParents.push(sbAncestor);+ }if (isUndo) {// https://github.com/siyuan-note/siyuan/issues/13617item.remove();@@ -333,6 +361,12 @@ const deleteBlock = (updateElements: Element[], id: string, protyle: IProtyle, iblockRender(protyle, item);}});+ // 删除块后刷新所在超级块的拖拽手柄(被删块两侧的手柄需移除/重建)+ sbParents.forEach(sb => {+ if (sb.parentElement && getSbChildBlockCount(sb) > 1) {+ refreshSbResize(sb);+ }+ });};const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IOperation, isUndo: boolean) => {@@ -362,6 +396,12 @@ const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IOhighlightRender(item);avRender(item, protyle);blockRender(protyle, item);+ // 更新后刷新所在超级块的拖拽手柄(撤销/重做可能整体替换超级块 DOM)+ // https://github.com/siyuan-note/siyuan/issues/9521+ const updatedSb = item.closest('[data-type="NodeSuperBlock"]');+ if (updatedSb) {+ refreshSbResize(updatedSb);+ }});};@@ -414,6 +454,14 @@ export const onTransaction = (protyle: IProtyle, operations: IOperation[], isUndhighlightRender(protyle.wysiwyg.element);avRender(protyle.wysiwyg.element, protyle);blockRender(protyle, protyle.wysiwyg.element);+ // 展开标题插入的块可能落在超级块内,刷新手柄避免与既有手柄重复/错位+ // https://github.com/siyuan-note/siyuan/issues/9521+ protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach(item => {+ const sbAncestor = item.closest('[data-type="NodeSuperBlock"]');+ if (sbAncestor) {+ refreshSbResize(sbAncestor);+ }+ });}return;}@@ -444,6 +492,14 @@ export const onTransaction = (protyle: IProtyle, operations: IOperation[], isUndblockRender(protyle, embedElement);}});+ // 折叠移除子块后,刷新折叠标题所在超级块的拖拽手柄(子块数变化)+ // https://github.com/siyuan-note/siyuan/issues/9521+ protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach(item => {+ const sbAncestor = item.closest('[data-type="NodeSuperBlock"]');+ if (sbAncestor) {+ refreshSbResize(sbAncestor);+ }+ });if (protyle.wysiwyg.element.childElementCount === 0) {zoomOut({protyle,@@ -773,6 +829,16 @@ export const onTransaction = (protyle: IProtyle, operations: IOperation[], isUnd}});}+ // 移动块(含重做/同步)后刷新相关超级块的拖拽手柄 https://github.com/siyuan-note/siyuan/issues/9521+ [operation.id, operation.parentID, operation.previousID].forEach(blockId => {+ if (blockId) {+ const el = protyle.wysiwyg.element.querySelector(`[data-node-id="${blockId}"]`);+ const sbAncestor = el?.closest('[data-type="NodeSuperBlock"]');+ if (sbAncestor) {+ refreshSbResize(sbAncestor);+ }+ }+ });return;}if (operation.action === "insert") {@@ -870,6 +936,12 @@ export const onTransaction = (protyle: IProtyle, operations: IOperation[], isUndhighlightRender(item);avRender(item, protyle);blockRender(protyle, item);+ // 插入块后刷新所在超级块的拖拽手柄(撤销/重做/同步)+ // https://github.com/siyuan-note/siyuan/issues/9521+ const insertSb = item.closest('[data-type="NodeSuperBlock"]');+ if (insertSb) {+ refreshSbResize(insertSb);+ }const wbrElement = item.querySelector("wbr");if (isUndo) {if (operation.context?.setRange === "true") {@@ -1057,7 +1129,7 @@ export const turnsIntoOneTransaction = async (options: {refreshSbResize(parentElement.parentElement);}if ((["Blocks2Blockquote", "Blocks2Callout"].includes(options.type) || options.type.endsWith("Ls")) &&- parentElement.parentElement.classList.contains("sb") && getSbChildCount(parentElement.parentElement) === 1) {+ parentElement.parentElement.classList.contains("sb") && getSbChildBlockCount(parentElement.parentElement) === 1) {const cancelOperations = await cancelSB(options.protyle, parentElement.parentElement);doOperations.push(...cancelOperations.doOperations);undoOperations.splice(0, 0, ...cancelOperations.undoOperations);@@ -1432,6 +1504,14 @@ const processFold = (operation: IOperation, protyle: IProtyle) => {highlightRender(protyle.wysiwyg.element);avRender(protyle.wysiwyg.element, protyle);blockRender(protyle, protyle.wysiwyg.element);+ // 展开标题插入的块可能落在超级块内,刷新手柄避免与既有手柄重复/错位+ // https://github.com/siyuan-note/siyuan/issues/9521+ protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach(item => {+ const sbAncestor = item.closest('[data-type="NodeSuperBlock"]');+ if (sbAncestor) {+ refreshSbResize(sbAncestor);+ }+ });if (operation.context?.focusId) {const focusElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${operation.context.focusId}"]`);focusBlock(focusElement);@@ -1449,6 +1529,14 @@ const processFold = (operation: IOperation, protyle: IProtyle) => {blockRender(protyle, embedElement);}});+ // 折叠移除子块后,刷新折叠标题所在超级块的拖拽手柄(子块数变化)+ // https://github.com/siyuan-note/siyuan/issues/9521+ protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach(item => {+ const sbAncestor = item.closest('[data-type="NodeSuperBlock"]');+ if (sbAncestor) {+ refreshSbResize(sbAncestor);+ }+ });// 折叠标题后未触发动态加载 https://github.com/siyuan-note/siyuan/issues/4168if (protyle.wysiwyg.element.lastElementChild.getAttribute("data-eof") !== "2" &&!protyle.scroll.element.classList.contains("fn__none") &&diff --git a/app/src/util/functions.ts b/app/src/util/functions.tsindex 8ae692768f..7aedcdc39d 100644--- a/app/src/util/functions.ts+++ b/app/src/util/functions.ts@@ -112,7 +112,7 @@ export const duplicateNameAddOne = (name: string) => {};/// #if !BROWSER-// 红绿灯为原生控件不随缩放变化,缩小时按 zoom 补偿 --b3-toolbar-left-mac 避免与工具栏内容重叠 https://github.com/siyuan-note/siyuan/issues/9521+// 红绿灯为原生控件不随缩放变化,缩小时按 zoom 补偿 --b3-toolbar-left-mac 避免与工具栏内容重叠export const setToolbarLeftMac = (zoom: number) => {// 非桌面端、非 macOS 不补偿(让 body--win32 的 class 规则生效)if (!window.siyuan.config || getBackend() !== "darwin") {