From 7b38c9a108802a2ba0acc41e22b9cc31e22bde90 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 22 Nov 2024 17:24:12 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/13170 --- app/src/layout/dock/Files.ts | 58 ++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.ts index 64bfde942..b6683016b 100644 --- a/app/src/layout/dock/Files.ts +++ b/app/src/layout/dock/Files.ts @@ -483,19 +483,17 @@ export class Files extends Model { } } if (gutterType) { + // 块标拖拽 const gutterTypes = gutterType.replace(Constants.SIYUAN_DROP_GUTTER, "").split(Constants.ZWSP); - if (["nodelistitem", "nodeheading"].includes(gutterTypes[0])) { - // 块标拖拽 - liElement.classList.add("dragover"); + if (!["nodelistitem", "nodeheading"].includes(gutterTypes[0])) { + event.preventDefault(); + return; } - event.preventDefault(); + } else if (liElement.classList.contains("b3-list-item--focus")) { + // 选中的文档不能拖拽到自己上,但允许标题拖拽到文档树的选中文档上 https://github.com/siyuan-note/siyuan/issues/6552 return; } - // 允许标题拖拽到文档树的选中文档上 https://github.com/siyuan-note/siyuan/issues/6552 - if (liElement.classList.contains("b3-list-item--focus")) { - return; - } - let sourceOnlyRoot = true; + let sourceOnlyRoot = gutterType ? false : true; Array.from(this.element.querySelectorAll(".b3-list-item--focus")).find((item: HTMLElement) => { if (item.getAttribute("data-type") === "navigation-file") { sourceOnlyRoot = false; @@ -566,24 +564,38 @@ export class Files extends Model { gutterType = item.type; } } - if (gutterType && newElement.classList.contains("dragover")) { + // 块标拖拽 + if (gutterType) { const gutterTypes = gutterType.replace(Constants.SIYUAN_DROP_GUTTER, "").split(Constants.ZWSP); if (["nodelistitem", "nodeheading"].includes(gutterTypes[0])) { - // 块标拖拽 + const toDocOptions: { + targetNoteBook: string; + pushMode: number; + srcHeadingID?: string; + srcListItemID?: string; + targetPath?: string; + previousPath?: string; + } = { + targetNoteBook: toURL, + pushMode: 0, + }; + if (newElement.classList.contains("dragover")) { + toDocOptions.targetPath = toPath; + } else if (newElement.classList.contains("dragover__bottom")) { + toDocOptions.previousPath = toPath; + } else if (newElement.classList.contains("dragover__top")) { + if (newElement.previousElementSibling) { + toDocOptions.previousPath = newElement.previousElementSibling.getAttribute("data-path"); + } else { + toDocOptions.targetPath = newElement.parentElement.previousElementSibling.getAttribute("data-path"); + } + } if (gutterTypes[0] === "nodeheading") { - fetchPost("/api/filetree/heading2Doc", { - targetNoteBook: toURL, - srcHeadingID: gutterTypes[2].split(",")[0], - targetPath: toPath, - pushMode: 0, - }); + toDocOptions.srcHeadingID = gutterTypes[2].split(",")[0]; + fetchPost("/api/filetree/heading2Doc", toDocOptions); } else { - fetchPost("/api/filetree/li2Doc", { - pushMode: 0, - srcListItemID: gutterTypes[2].split(",")[0], - targetNoteBook: toURL, - targetPath: toPath - }); + toDocOptions.srcListItemID = gutterTypes[2].split(",")[0]; + fetchPost("/api/filetree/li2Doc", toDocOptions); } } newElement.classList.remove("dragover", "dragover__bottom", "dragover__top");