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 nested super block column reordering https://github.com/siyuan-note/siyuan/issues/18174
Daniel8bbdf876f996
diff --git a/app/src/protyle/util/dragDocument.test.ts b/app/src/protyle/util/dragDocument.test.tsindex 5b892f2da0..d553e87b35 100644--- a/app/src/protyle/util/dragDocument.test.ts+++ b/app/src/protyle/util/dragDocument.test.ts@@ -3,6 +3,7 @@ import * as assert from "node:assert/strict";import {getAVRowDropTarget,getSameSuperBlockEdgeTarget,+ getSuperBlockResizeDropTarget,getTopListDragTarget,isAttributeViewTitleTarget,isDragTargetInSource,@@ -201,6 +202,30 @@ describe("getSameSuperBlockEdgeTarget", () => {});});+describe("getSuperBlockResizeDropTarget", () => {+ it("uses the previous column for a horizontal super block resize handle", () => {+ const {blocks, superBlock} = createSuperBlock();+ const resize = {+ classList: {contains: (className: string) => className === "sb__resize"},+ parentElement: superBlock,+ previousElementSibling: blocks[1],+ } as unknown as HTMLElement;++ assert.equal(getSuperBlockResizeDropTarget(resize), blocks[1]);+ });++ it("ignores resize handles outside a horizontal super block", () => {+ const {blocks, superBlock} = createSuperBlock("row");+ const resize = {+ classList: {contains: (className: string) => className === "sb__resize"},+ parentElement: superBlock,+ previousElementSibling: blocks[1],+ } as unknown as HTMLElement;++ assert.equal(getSuperBlockResizeDropTarget(resize), undefined);+ });+});+describe("getTopListDragTarget", () => {it("uses the complete list when a list item is hit at the outer edge", () => {const list = createClassElement(["list"]);diff --git a/app/src/protyle/util/dragDocument.ts b/app/src/protyle/util/dragDocument.tsindex 9cbf219cb6..76c314ecb6 100644--- a/app/src/protyle/util/dragDocument.ts+++ b/app/src/protyle/util/dragDocument.ts@@ -75,6 +75,22 @@ export const getSameSuperBlockEdgeTarget = (sourceElements: Element[], targetElereturn childBlocks[isRight ? childBlocks.length - 1 : 0];};+export const getSuperBlockResizeDropTarget = (resizeElement: HTMLElement | false): HTMLElement | undefined => {+ if (!resizeElement || !resizeElement.classList.contains("sb__resize")) {+ return;+ }+ const superBlock = resizeElement.parentElement;+ if (superBlock?.getAttribute("data-type") !== "NodeSuperBlock" ||+ superBlock.getAttribute("data-sb-layout") !== "col") {+ return;+ }+ let targetElement = resizeElement.previousElementSibling as HTMLElement;+ while (targetElement && !targetElement.hasAttribute("data-node-id")) {+ targetElement = targetElement.previousElementSibling as HTMLElement;+ }+ return targetElement;+};+export const getTopListDragTarget = (targetElement: Element) => {let topList = targetElement;while (topList.parentElement?.classList.contains("li") ||diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex 0c557c90b5..c49ec10663 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -56,6 +56,7 @@ import {isEncryptedBox} from "../../util/pathName";import {getAVRowDropTarget,getSameSuperBlockEdgeTarget,+ getSuperBlockResizeDropTarget,getTopListDragTarget,isAttributeViewTitleTarget,isDragTargetInSource,@@ -2374,7 +2375,9 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {hideCaretLine();// 编辑器内文字拖拽或资源文件拖拽或按住 alt/shift 拖拽反链图标进入编辑器时不能运行 event.preventDefault(), 否则无光标; 需放在 !window.siyuan.dragElement 之后event.preventDefault();- targetElement = hasClosestByClassName(event.target, "av__gallery-item") || hasClosestByClassName(event.target, "av__gallery-add") ||+ const superBlockResizeElement = hasClosestByClassName(event.target, "sb__resize");+ const superBlockResizeTarget = getSuperBlockResizeDropTarget(superBlockResizeElement);+ targetElement = superBlockResizeTarget || hasClosestByClassName(event.target, "av__gallery-item") || hasClosestByClassName(event.target, "av__gallery-add") ||hasClosestByClassName(event.target, "av__row") || hasClosestByClassName(event.target, "av__row--util") ||hasClosestBlock(event.target);targetElement = getAVRowDropTarget(targetElement);@@ -2383,7 +2386,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {// 拖拽到属性视图 gallery 内,但没选中 itemreturn;}- const point = {x: event.clientX, y: event.clientY, className: ""};+ // 横排超级块的调整手柄位于两个直接子块之间,拖拽块经过时表示插入到前一列之后。+ const point = {x: event.clientX, y: event.clientY, className: superBlockResizeTarget ? "dragover__right" : ""};// 超级块中有a,b两个段落块,移动到 ab 之间的间隙 targetElement 会变为超级块,需修正为 aif (targetElement && (targetElement.classList.contains("bq") || targetElement.classList.contains("sb") || targetElement.classList.contains("list") || targetElement.classList.contains("li"))) {