From 91ece28b33476e1aaf4294a76011c296cf9c1f85 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 20 Jan 2024 21:27:23 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/10142 --- app/src/protyle/render/av/blockAttr.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/src/protyle/render/av/blockAttr.ts b/app/src/protyle/render/av/blockAttr.ts index e20a8162e..a720be4d3 100644 --- a/app/src/protyle/render/av/blockAttr.ts +++ b/app/src/protyle/render/av/blockAttr.ts @@ -195,24 +195,30 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone"].includes ghostElement.remove(); }); }); - element.addEventListener("drop", (event) => { + element.addEventListener("drop", () => { window.siyuan.dragElement.style.opacity = ""; - const id = window.siyuan.dragElement.dataset.colId; - window.siyuan.dragElement = null; const targetElement = element.querySelector(".dragover__bottom, .dragover__top") as HTMLElement - if (!targetElement) { - return; - } - const previousID = targetElement.classList.contains("dragover__bottom") ? targetElement.dataset.colId : targetElement.previousElementSibling?.getAttribute("data-col-id"); - targetElement.classList.remove("dragover__bottom", "dragover__top"); - if (dragBlockElement) { + if (targetElement && dragBlockElement) { + const isBottom = targetElement.classList.contains("dragover__bottom"); transaction(protyle, [{ action: "sortAttrViewCol", avID: dragBlockElement.dataset.avId, - previousID, + previousID:isBottom ? targetElement.dataset.colId : targetElement.previousElementSibling?.getAttribute("data-col-id"), + id: window.siyuan.dragElement.dataset.colId, + }, { + action: "sortAttrViewCol", + avID: dragBlockElement.dataset.avId, + previousID: window.siyuan.dragElement.previousElementSibling?.getAttribute("data-col-id"), id }]); + if (isBottom) { + targetElement.after(window.siyuan.dragElement) + } else { + targetElement.before(window.siyuan.dragElement) + } + targetElement.classList.remove("dragover__bottom", "dragover__top"); } + window.siyuan.dragElement = null; }); element.addEventListener("dragover", (event: DragEvent) => { const target = event.target as HTMLElement;