Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Hide block gutters while dragging https://github.com/siyuan-note/siyuan/issues/14860

Daniel0f96835d9887
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scss
index 3b8df9aedf..9cc4cd5214 100644
--- a/app/src/assets/scss/protyle/_protyle.scss
+++ b/app/src/assets/scss/protyle/_protyle.scss
@@ -79,6 +79,11 @@
z-index: 1;
text-align: center;
+ &--dragging {
+ opacity: 0;
+ pointer-events: none;
+ }
+
button {
border: 0;
background-color: transparent;
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index cb2191aa80..c08c3d046a 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -133,6 +133,16 @@ export class Gutter {
}
this.element = document.createElement("div");
this.element.className = "protyle-gutters";
+ let isGutterDragging = false;
+ let dragCleanupController: AbortController | undefined;
+ const restoreGutter = () => {
+ isGutterDragging = false;
+ this.element.classList.remove("protyle-gutters--dragging");
+ window.siyuan.dragElement = undefined;
+ window.siyuan.dragTitle = "";
+ dragCleanupController?.abort();
+ dragCleanupController = undefined;
+ };
this.element.addEventListener("dragstart", (event: DragEvent & { target: HTMLElement }) => {
hideTooltip();
window.siyuan.menus.menu.remove();
@@ -240,18 +250,33 @@ export class Gutter {
}
window.siyuan.dragTitle = title;
}
- buttonElement.style.opacity = "0.38";
window.siyuan.dragElement = avElement as HTMLElement || protyle.wysiwyg.element;
event.dataTransfer.setData(`${Constants.SIYUAN_DROP_GUTTER}${buttonElement.getAttribute("data-type")}${Constants.ZWSP}${buttonElement.getAttribute("data-subtype")}${Constants.ZWSP}${selectIds}${Constants.ZWSP}${window.siyuan.config.system.workspaceDir}`,
protyle.wysiwyg.element.innerHTML);
- });
- this.element.addEventListener("dragend", () => {
- this.element.querySelectorAll("button").forEach((item) => {
- item.style.opacity = "";
+ isGutterDragging = true;
+ dragCleanupController?.abort();
+ const cleanupController = new AbortController();
+ dragCleanupController = cleanupController;
+ window.addEventListener("drop", () => {
+ setTimeout(() => {
+ if (dragCleanupController === cleanupController) {
+ restoreGutter();
+ }
+ });
+ }, {capture: true, once: true, signal: cleanupController.signal});
+ window.addEventListener("dragend", restoreGutter, {
+ capture: true,
+ once: true,
+ signal: cleanupController.signal,
+ });
+ window.addEventListener("blur", restoreGutter, {once: true, signal: cleanupController.signal});
+ setTimeout(() => {
+ if (isGutterDragging && dragCleanupController === cleanupController) {
+ this.element.classList.add("protyle-gutters--dragging");
+ }
});
- window.siyuan.dragElement = undefined;
- window.siyuan.dragTitle = "";
});
+ this.element.addEventListener("dragend", restoreGutter);
this.element.addEventListener("click", (event: MouseEvent & { target: HTMLInputElement }) => {
const buttonElement = hasClosestByTag(event.target, "BUTTON");
if (!buttonElement) {
diff --git a/app/src/util/touchDragBridge.ts b/app/src/util/touchDragBridge.ts
index 98d8d3f7ff..7ca47ece1f 100644
--- a/app/src/util/touchDragBridge.ts
+++ b/app/src/util/touchDragBridge.ts
@@ -276,6 +276,7 @@ const handlePointerMove = (event: PointerEvent) => {
return;
}
if ((event.buttons & 1) === 0) {
+ dispatchBridgeDragEnd(event);
cleanupDrag();
return;
}
@@ -311,6 +312,7 @@ const handlePointerUp = (event: PointerEvent) => {
const handlePointerCancel = (event: PointerEvent) => {
if (dragState?.inputType === "pointer" && dragState.pointerId === event.pointerId) {
+ dispatchBridgeDragEnd(event);
cleanupDrag();
}
};
@@ -457,11 +459,17 @@ const endBridgeDrag = (touch: DragPoint) => {
elementUnderTouch.dispatchEvent(dropEvent);
}
+ dispatchBridgeDragEnd(touch);
+};
+
+const dispatchBridgeDragEnd = (point?: DragPoint) => {
+ if (!dragState?.isDragging) return;
+
const dragEndEvent = new DragEvent("dragend", {
bubbles: true,
cancelable: true,
- clientX: touch.clientX,
- clientY: touch.clientY,
+ clientX: point?.clientX ?? dragState.startX,
+ clientY: point?.clientY ?? dragState.startY,
dataTransfer: dragState.dataTransfer,
view: window,
});
@@ -486,6 +494,7 @@ const cleanupDrag = () => {
};
const handleCancel = () => {
+ dispatchBridgeDragEnd();
// touchcancel 时两条路径都需无条件清理(cleanupDrag/cancelManualTouch 内部均做空状态处理)
cleanupDrag();
cancelManualTouch();
@@ -516,6 +525,7 @@ export const initTouchDragBridge = () => {
document.addEventListener("click", handleMouseClick, {capture: true, passive: false});
window.addEventListener("blur", () => {
if (dragState?.inputType === "pointer") {
+ dispatchBridgeDragEnd();
cleanupDrag();
}
});