diff --git a/app/src/boot/globalEvent/dragover.ts b/app/src/boot/globalEvent/dragover.ts index b9a7fae83..177bb833a 100644 --- a/app/src/boot/globalEvent/dragover.ts +++ b/app/src/boot/globalEvent/dragover.ts @@ -30,6 +30,7 @@ const dragoverScroll: { space?: number // -1 向上;1 向下 lastTime?: number } = {}; + export const stopScrollAnimation = () => { if (dragoverScroll.animationId) { cancelAnimationFrame(dragoverScroll.animationId); @@ -39,6 +40,7 @@ export const stopScrollAnimation = () => { dragoverScroll.lastTime = null; } }; + const scrollAnimation = (timestamp: number) => { if (!dragoverScroll.lastTime) { dragoverScroll.lastTime = timestamp - 8; diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index d0a79a37e..02a4ac3bd 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -63,6 +63,7 @@ import * as path from "path"; /// #endif import {checkFold} from "../../util/noRelyPCFunction"; import {clearSelect} from "../util/clear"; +import {stopScrollAnimation} from "../../boot/globalEvent/dragover"; export class Gutter { public element: HTMLElement; @@ -183,6 +184,7 @@ export class Gutter { item.style.opacity = ""; }); window.siyuan.dragElement = undefined; + stopScrollAnimation(); }); this.element.addEventListener("click", (event: MouseEvent & { target: HTMLInputElement }) => { const buttonElement = hasClosestByTag(event.target, "BUTTON"); diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts index 30eb9fec6..f690a7c52 100644 --- a/app/src/protyle/util/editorCommonEvent.ts +++ b/app/src/protyle/util/editorCommonEvent.ts @@ -36,6 +36,7 @@ import {processClonePHElement} from "../render/util"; import {insertGalleryItemAnimation} from "../render/av/gallery/item"; import {clearSelect} from "./clear"; import {dragoverTab} from "../render/av/view"; +import {dragOverScroll, stopScrollAnimation} from "../../boot/globalEvent/dragover"; // position: afterbegin 为拖拽成超级块; "afterend", "beforebegin" 一般拖拽 const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElement: Element, @@ -1174,6 +1175,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => { window.siyuan.dragElement.style.opacity = ""; window.siyuan.dragElement = undefined; } + stopScrollAnimation(); }); let dragoverElement: Element; let disabledPosition: string; @@ -1196,12 +1198,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => { return; } const contentRect = protyle.contentElement.getBoundingClientRect(); - if (!hasClosestByClassName(event.target, "av__cell") && - (event.clientY < contentRect.top + Constants.SIZE_SCROLL_TB || event.clientY > contentRect.bottom - Constants.SIZE_SCROLL_TB)) { - protyle.contentElement.scroll({ - top: protyle.contentElement.scrollTop + (event.clientY < contentRect.top + Constants.SIZE_SCROLL_TB ? -Constants.SIZE_SCROLL_STEP : Constants.SIZE_SCROLL_STEP), - behavior: "smooth" - }); + if (!hasClosestByClassName(event.target, "av__cell")) { + dragOverScroll(event, contentRect, protyle.contentElement); } let targetElement: HTMLElement | false; // 设置了的话 drop 就无法监听 shift/control event.dataTransfer.dropEffect = "move"; @@ -1597,6 +1595,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => { window.siyuan.dragElement = undefined; document.onmousemove = null; } + stopScrollAnimation(); }); };