An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Make document tab drop options direct hit targets https://github.com/siyuan-note/siyuan/issues/19114
Daniel2894eb4c32f5
diff --git a/app/src/assets/scss/business/_layout.scss b/app/src/assets/scss/business/_layout.scssindex 1750d7c8c4..12d740b6d9 100644--- a/app/src/assets/scss/business/_layout.scss+++ b/app/src/assets/scss/business/_layout.scss@@ -203,44 +203,6 @@background-color: var(--b3-theme-primary-lightest);}- &-bars--document-drop {- position: relative;-- > .item__document-drop {- align-items: stretch;- background-color: var(--b3-theme-background);- border-radius: var(--b3-border-radius);- box-shadow: 0 0 0 1px var(--b3-theme-primary-lighter) inset, var(--b3-point-shadow);- direction: ltr;- display: flex;- max-width: calc(100% - 8px);- overflow: hidden;- position: absolute;- transform: translateX(-50%);- width: 200px;- z-index: 4;-- .item__document-drop-option {- align-items: center;- direction: initial;- display: flex;- flex: 1;- font-size: 12px;- justify-content: center;- min-width: 0;- overflow: hidden;- padding: 0 8px;- text-overflow: ellipsis;- white-space: nowrap;-- &--active {- background-color: var(--b3-theme-primary-lightest);- color: var(--b3-theme-primary);- }- }- }- }-&-bar {list-style: none;align-items: center;@@ -281,14 +243,49 @@pointer-events: none;}+ &--full {+ max-width: none;+ flex: 1;+ }+&--document-drop {cursor: grabbing;+ flex: 0 0 200px;+ max-width: 200px;+ transition: none;+ width: 200px;z-index: 3;- }- &--full {- max-width: none;- flex: 1;+ > .item__document-drop {+ align-items: stretch;+ background-color: var(--b3-theme-background);+ border-radius: var(--b3-border-radius);+ box-shadow: 0 0 0 1px var(--b3-theme-primary-lighter) inset, var(--b3-point-shadow);+ direction: ltr;+ display: flex;+ inset: 0;+ overflow: hidden;+ position: absolute;++ .item__document-drop-option {+ align-items: center;+ direction: initial;+ display: flex;+ flex: 1;+ font-size: 12px;+ justify-content: center;+ min-width: 0;+ overflow: hidden;+ padding: 0 8px;+ text-overflow: ellipsis;+ white-space: nowrap;++ &--active {+ background-color: var(--b3-theme-primary-lightest);+ color: var(--b3-theme-primary);+ }+ }+ }}&:hover:not(.item--focus):not(.item--readonly) {diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.tsindex fbfc761ec6..76698624aa 100644--- a/app/src/layout/Wnd.ts+++ b/app/src/layout/Wnd.ts@@ -57,9 +57,7 @@ import {clearTabHoverSwitch,findDefaultTabNextId,findNextTabId,- getDocumentTabMovePreviewLeft,getDocumentTabMovePosition,- isDocumentTabMovePreviewPoint,reorderTabItems,scheduleTabHoverSwitch} from "./tabDrag";@@ -71,15 +69,8 @@ interface IDocumentTabMoveTarget {rootID: string;}-const getDocumentTabMoveTarget = (target: HTMLElement, headersElement: HTMLElement, clientX: number, clientY: number) => {- const previewElement = headersElement.parentElement.querySelector<HTMLElement>(":scope > .item__document-drop");- const previewRect = previewElement?.getBoundingClientRect();- const dropElement = hasClosestByClassName(target, "item__document-drop") ||- (previewElement && previewRect && isDocumentTabMovePreviewPoint(clientX, clientY, previewRect.left,- previewRect.top, previewRect.width, previewRect.height) ? previewElement : undefined);- const tabHeaderElement = dropElement ? (Array.from(headersElement.children) as HTMLElement[]).find((item) =>- item.dataset.id === dropElement.dataset.targetTabId) :- hasClosestByAttribute(target, "data-type", "tab-header");+const getDocumentTabMoveTarget = (target: HTMLElement, headersElement: HTMLElement) => {+ const tabHeaderElement = hasClosestByAttribute(target, "data-type", "tab-header");if (!tabHeaderElement || !headersElement.contains(tabHeaderElement)) {return;}@@ -98,26 +89,19 @@ const getDocumentTabMoveTarget = (target: HTMLElement, headersElement: HTMLEleme};const updateDocumentTabMovePreview = (target: IDocumentTabMoveTarget, tabHeadersElement: HTMLElement, clientX: number) => {- let dropElement = tabHeadersElement.querySelector<HTMLElement>(":scope > .item__document-drop");+ let dropElement = target.element.querySelector<HTMLElement>(":scope > .item__document-drop");if (!target.element.classList.contains("item--document-drop") || !dropElement) {clearDocumentTabMovePreview();target.element.classList.add("item--document-drop");tabHeadersElement.classList.add("layout-tab-bars--document-drop");- tabHeadersElement.insertAdjacentHTML("beforeend", `<span class="item__document-drop" data-target-tab-id="${escapeHtml(target.element.dataset.id)}">+ target.element.insertAdjacentHTML("beforeend", `<span class="item__document-drop"><span class="item__document-drop-option" data-position="sibling">${escapeHtml(window.siyuan.languages.moveDocToSameLevel)}</span><span class="item__document-drop-option" data-position="child">${escapeHtml(window.siyuan.languages.moveDocAsChild)}</span></span>`);- dropElement = tabHeadersElement.querySelector<HTMLElement>(":scope > .item__document-drop");+ dropElement = target.element.querySelector<HTMLElement>(":scope > .item__document-drop");}- const headersRect = tabHeadersElement.getBoundingClientRect();- const targetRect = target.element.getBoundingClientRect();const rect = dropElement.getBoundingClientRect();- dropElement.style.left = `${getDocumentTabMovePreviewLeft(targetRect.left, targetRect.width, headersRect.left,- headersRect.width, rect.width)}px`;- dropElement.style.top = `${targetRect.top - headersRect.top}px`;- dropElement.style.height = `${targetRect.height}px`;- const positionedRect = dropElement.getBoundingClientRect();- const position = getDocumentTabMovePosition(clientX, positionedRect.left, positionedRect.width);+ const position = getDocumentTabMovePosition(clientX, rect.left, rect.width);target.element.dataset.documentDropPosition = position;dropElement.querySelectorAll<HTMLElement>(".item__document-drop-option").forEach((item) => {item.classList.toggle("item__document-drop-option--active", item.dataset.position === position);@@ -348,9 +332,8 @@ export class Wnd {}if (isFileDrag) {event.preventDefault();- if (event.shiftKey && isDocumentDrag) {- const documentTabTarget = getDocumentTabMoveTarget(event.target, this.headersElement,- event.clientX, event.clientY);+ if ((event.shiftKey || it.classList.contains("layout-tab-bars--document-drop")) && isDocumentDrag) {+ const documentTabTarget = getDocumentTabMoveTarget(event.target, this.headersElement);it.classList.remove("layout-tab-bars--drag");if (documentTabTarget) {updateDocumentTabMovePreview(documentTabTarget, it, event.clientX);@@ -417,12 +400,12 @@ export class Wnd {// 文档树拖拽const documentDragData = event.dataTransfer.types.includes(Constants.SIYUAN_DROP_DOCUMENTS) ?parseDocumentTreeDragData(event.dataTransfer.getData(Constants.SIYUAN_DROP_DOCUMENTS)) : undefined;- const documentTabTarget = getDocumentTabMoveTarget(event.target, it.firstElementChild as HTMLElement,- event.clientX, event.clientY);+ const documentMoveActive = event.shiftKey || it.classList.contains("layout-tab-bars--document-drop");+ const documentTabTarget = getDocumentTabMoveTarget(event.target, it.firstElementChild as HTMLElement);const movePosition = documentTabTarget?.element.dataset.documentDropPosition as"sibling" | "child" | undefined;setPanelFocus(it.parentElement);- if (event.shiftKey && documentDragData) {+ if (documentMoveActive && documentDragData) {event.preventDefault();event.stopPropagation();clearTabDragPreview(it);diff --git a/app/src/layout/tabDrag.test.ts b/app/src/layout/tabDrag.test.tsindex 6178667674..5aca8a3118 100644--- a/app/src/layout/tabDrag.test.ts+++ b/app/src/layout/tabDrag.test.ts@@ -1,9 +1,7 @@import {describe, it} from "node:test";import * as assert from "node:assert/strict";import {- getDocumentTabMovePreviewLeft,getDocumentTabMovePosition,- isDocumentTabMovePreviewPoint,clearTabHoverSwitch,findDefaultTabNextId,findNextTabId,@@ -18,15 +16,6 @@ describe("document tab move target", () => {assert.equal(getDocumentTabMovePosition(139, 100, 40), "child");});- it("keeps the preview inside the tab bar for a single narrow tab", () => {- assert.equal(getDocumentTabMovePreviewLeft(435, 68, 422, 538, 200), 104);- assert.equal(getDocumentTabMovePreviewLeft(700, 68, 422, 538, 200), 312);- });-- it("keeps both preview options available outside the original tab bounds", () => {- assert.equal(isDocumentTabMovePreviewPoint(620, 20, 438, 6, 200, 29), true);- assert.equal(isDocumentTabMovePreviewPoint(640, 20, 438, 6, 200, 29), false);- });});const createItems = () => [diff --git a/app/src/layout/tabDrag.ts b/app/src/layout/tabDrag.tsindex 3bbaabde2f..14d5726bb1 100644--- a/app/src/layout/tabDrag.ts+++ b/app/src/layout/tabDrag.ts@@ -3,18 +3,6 @@ export type TDocumentTabMovePosition = "sibling" | "child";export const getDocumentTabMovePosition = (clientX: number, left: number, width: number): TDocumentTabMovePosition =>clientX < left + width / 2 ? "sibling" : "child";-export const isDocumentTabMovePreviewPoint = (clientX: number, clientY: number, left: number, top: number,- width: number, height: number) =>- clientX >= left && clientX <= left + width && clientY >= top && clientY <= top + height;--export const getDocumentTabMovePreviewLeft = (targetLeft: number, targetWidth: number, containerLeft: number,- containerWidth: number, previewWidth: number, padding = 4) => {- const minLeft = previewWidth / 2 + padding;- const maxLeft = containerWidth - previewWidth / 2 - padding;- const preferredLeft = targetLeft - containerLeft + targetWidth / 2;- return Math.min(Math.max(preferredLeft, minLeft), Math.max(minLeft, maxLeft));-};-export const clearDocumentTabMovePreview = (tabHeadersElement?: ParentNode) => {const root = tabHeadersElement || document;root.querySelectorAll(".item__document-drop").forEach((item) => item.remove());