Vanessa 2023-02-08 12:39:43 +08:00
parent 0e7f68114d
commit 12847659d2
3 changed files with 5 additions and 2 deletions

View file

@ -16,6 +16,7 @@ export abstract class Constants {
// drop 事件 // drop 事件
public static readonly SIYUAN_DROP_FILE: string = "application/siyuan-file"; public static readonly SIYUAN_DROP_FILE: string = "application/siyuan-file";
public static readonly SIYUAN_DROP_GUTTER: string = "application/siyuan-gutter";
public static readonly SIYUAN_DROP_TAB: string = "application/siyuan-tab"; public static readonly SIYUAN_DROP_TAB: string = "application/siyuan-tab";
public static readonly SIYUAN_DROP_TABTOWINDOW: string = "application/siyuan-tabtowindow"; public static readonly SIYUAN_DROP_TABTOWINDOW: string = "application/siyuan-tabtowindow";
public static readonly SIYUAN_DROP_EDITOR: string = "application/siyuan-editor"; public static readonly SIYUAN_DROP_EDITOR: string = "application/siyuan-editor";

View file

@ -58,6 +58,7 @@ export class Gutter {
} }
event.target.style.opacity = "0.1"; event.target.style.opacity = "0.1";
window.siyuan.dragElement = event.target; window.siyuan.dragElement = event.target;
event.dataTransfer.setData(Constants.SIYUAN_DROP_GUTTER, selectIds.toString());
window.siyuan.dragElement.setAttribute("data-selected-ids", selectIds.toString()); window.siyuan.dragElement.setAttribute("data-selected-ids", selectIds.toString());
}); });
this.element.addEventListener("dragend", () => { this.element.addEventListener("dragend", () => {

View file

@ -708,6 +708,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
window.siyuan.dragElement = undefined; window.siyuan.dragElement = undefined;
event.preventDefault(); event.preventDefault();
} else { } else {
event.dataTransfer.setData(Constants.SIYUAN_DROP_GUTTER, target.parentElement.getAttribute("data-node-id"));
window.siyuan.dragElement = target.parentElement; window.siyuan.dragElement = target.parentElement;
} }
return; return;
@ -846,6 +847,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
event.preventDefault(); event.preventDefault();
return; return;
} }
// TODO !event.dataTransfer.types.includes(Constants.SIYUAN_DROP_GUTTER) https://github.com/siyuan-note/siyuan/issues/7284
if (!window.siyuan.dragElement) { if (!window.siyuan.dragElement) {
// https://github.com/siyuan-note/siyuan/issues/6436 // https://github.com/siyuan-note/siyuan/issues/6436
event.preventDefault(); event.preventDefault();
@ -865,7 +867,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
if (!targetElement) { if (!targetElement) {
return; return;
} }
const fileTreeIds = window.siyuan.dragElement.innerText; const fileTreeIds = window.siyuan.dragElement ? window.siyuan.dragElement.innerText || "";
if (targetElement && dragoverElement && targetElement.isSameNode(dragoverElement)) { if (targetElement && dragoverElement && targetElement.isSameNode(dragoverElement)) {
// 性能优化,目标为同一个元素不再进行校验 // 性能优化,目标为同一个元素不再进行校验
const nodeRect = targetElement.getBoundingClientRect(); const nodeRect = targetElement.getBoundingClientRect();
@ -901,7 +903,6 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
} }
return; return;
} }
if (window.siyuan.dragElement.parentElement?.classList.contains("protyle-gutters") || if (window.siyuan.dragElement.parentElement?.classList.contains("protyle-gutters") ||
// 列表项之前的点 // 列表项之前的点
window.siyuan.dragElement.getAttribute("data-type") === "NodeListItem") { window.siyuan.dragElement.getAttribute("data-type") === "NodeListItem") {