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
Vanessad396fda66758
diff --git a/app/src/block/util.ts b/app/src/block/util.tsindex 93591f7b08..ac9e846563 100644--- a/app/src/block/util.ts+++ b/app/src/block/util.ts@@ -195,7 +195,7 @@ export const jumpToParent = (protyle: IProtyle, nodeElement: Element, type: "par});};-export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id?: string) => {+export const insertEmptyBlock = async (protyle: IProtyle, position: InsertPosition, id?: string) => {const range = getEditorRange(protyle.wysiwyg.element);let blockElement: Element;if (id) {@@ -263,20 +263,25 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, idpreviousID: blockElement.getAttribute("data-node-id"),}];}- transaction(protyle, doOperations, [{+ const undoOperations: IOperation[] = [{action: "delete",id: newId,- }]);- }- if (blockElement.parentElement.classList.contains("sb") &&- blockElement.parentElement.getAttribute("data-sb-layout") === "col") {- turnsIntoOneTransaction({- protyle,- selectsElement: position === "afterend" ? [blockElement, blockElement.nextElementSibling] : [blockElement.previousElementSibling, blockElement],- type: "BlocksMergeSuperBlock",- level: "row",- unfocus: true,- });+ }];+ if (blockElement.parentElement.classList.contains("sb") &&+ blockElement.parentElement.getAttribute("data-sb-layout") === "col") {+ // 合并到同一个 transaction,避免新超级块 id 在第二个 transaction 中找不到+ const mergeOperations = await turnsIntoOneTransaction({+ protyle,+ selectsElement: position === "afterend" ? [blockElement, blockElement.nextElementSibling] : [blockElement.previousElementSibling, blockElement],+ type: "BlocksMergeSuperBlock",+ level: "row",+ unfocus: true,+ getOperations: true,+ });+ doOperations.push(...mergeOperations.doOperations);+ undoOperations.splice(0, 0, ...mergeOperations.undoOperations);+ }+ transaction(protyle, doOperations, undoOperations);}focusByWbr(protyle.wysiwyg.element, range);scrollCenter(protyle);diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex 5f3fe832b4..8dae2b501c 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -590,22 +590,26 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElemdragSbSet.forEach(sb => {refreshSbAndPersistWidth(sb, doOperations, undoOperations);});- if (isSameDoc || isCopy) {- transaction(protyle, doOperations, undoOperations);- } else {- // 跨文档移动为可逆条目:全局撤销栈按 rootID 分栈联动,撤销时经 mutatedRootIDs 判定弹确认- transaction(protyle, doOperations, undoOperations);- }if ((newSourceParentElement.length > 1 || hasFoldHeading) &&newSourceParentElement[0].parentElement.classList.contains("sb") &&newSourceParentElement[0].parentElement.getAttribute("data-sb-layout") === "col") {- turnsIntoOneTransaction({+ // 合并到同一个 transaction,避免新超级块 id 在第二个 transaction 中找不到+ const mergeOperations = await turnsIntoOneTransaction({protyle,selectsElement: newSourceParentElement.reverse(),type: "BlocksMergeSuperBlock",level: "row",unfocus: true,+ getOperations: true});+ doOperations.push(...mergeOperations.doOperations);+ undoOperations.splice(0, 0, ...mergeOperations.undoOperations);+ }+ if (isSameDoc || isCopy) {+ transaction(protyle, doOperations, undoOperations);+ } else {+ // 跨文档移动为可逆条目:全局撤销栈按 rootID 分栈联动,撤销时经 mutatedRootIDs 判定弹确认+ transaction(protyle, doOperations, undoOperations);}if (document.contains(sourceElements[0])) {focusBlock(sourceElements[0]);diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.tsindex ad9a032da3..ab09d889ee 100644--- a/app/src/protyle/wysiwyg/list.ts+++ b/app/src/protyle/wysiwyg/list.ts@@ -465,7 +465,7 @@ export const breakList = (protyle: IProtyle, blockElement: Element, range: Range* @param isDelete* @param deleteElement 末尾反向删除时才会传入*/-export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: Range, isDelete = false, deleteElement?: Element) => {+export const listOutdent = async (protyle: IProtyle, liItemElements: Element[], range: Range, isDelete = false, deleteElement?: Element) => {liItemElements.forEach(item => {item.removeAttribute("select-start");item.removeAttribute("select-end");@@ -640,17 +640,21 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:data: movedHTML,});}- transaction(protyle, topDoOperations, topUndoOperations);if (liElement.childElementCount !== 1 && parentLiItemElement.classList.contains("sb") &&parentLiItemElement.getAttribute("data-sb-layout") === "col") {- turnsIntoOneTransaction({+ // 合并到同一个 transaction,避免新超级块 id 在第二个 transaction 中找不到+ const mergeOperations = await turnsIntoOneTransaction({protyle,selectsElement: [liElement, liElement.nextElementSibling],type: "BlocksMergeSuperBlock",level: "row",unfocus: true,+ getOperations: true,});+ topDoOperations.push(...mergeOperations.doOperations);+ topUndoOperations.splice(0, 0, ...mergeOperations.undoOperations);}+ transaction(protyle, topDoOperations, topUndoOperations);focusByWbr(parentLiItemElement, range);return;}diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.tsindex ea62f16c8e..33c1d13ea2 100644--- a/app/src/protyle/wysiwyg/remove.ts+++ b/app/src/protyle/wysiwyg/remove.ts@@ -683,7 +683,7 @@ export const removeImage = (imgSelectElement: Element, nodeElement: HTMLElement,}};-const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDelete = false) => {+const removeLi = async (protyle: IProtyle, blockElement: Element, range: Range, isDelete = false) => {if (!blockElement.parentElement.previousElementSibling && blockElement.parentElement.nextElementSibling && blockElement.parentElement.nextElementSibling.classList.contains("protyle-attr")) {listOutdent(protyle, [blockElement.parentElement], range, isDelete, blockElement);return;@@ -768,7 +768,6 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDeledata: listHTML,id: listElement.getAttribute("data-node-id"),});- transaction(protyle, doOperations, undoOperations);if (listElement.parentElement.classList.contains("sb") &&listElement.parentElement.getAttribute("data-sb-layout") === "col") {const selectsElement: Element[] = [];@@ -780,14 +779,19 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDele}previousElement = previousElement.previousElementSibling;}- turnsIntoOneTransaction({+ // 合并到同一个 transaction,避免新超级块 id 在第二个 transaction 中找不到+ const mergeOperations = await turnsIntoOneTransaction({protyle,selectsElement: selectsElement.reverse(),type: "BlocksMergeSuperBlock",level: "row",unfocus: true,+ getOperations: true,});+ doOperations.push(...mergeOperations.doOperations);+ undoOperations.splice(0, 0, ...mergeOperations.undoOperations);}+ transaction(protyle, doOperations, undoOperations);focusByWbr(protyle.wysiwyg.element, range);return;}