Skip to content

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

:art: 页签拖拽 https://github.com/siyuan-note/siyuan/issues/2955

Vanessac3f651b6c9b3
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 5615f4b464..b48d551b5c 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -17,6 +17,7 @@ export abstract class Constants {
// drop 事件
public static readonly SIYUAN_DROP_FILE: string = "application/siyuan-file";
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_EDITOR: string = "application/siyuan-editor";
// 渲染进程调主进程
diff --git a/app/src/layout/Tab.ts b/app/src/layout/Tab.ts
index ef44fc4aec..1435f093dc 100644
--- a/app/src/layout/Tab.ts
+++ b/app/src/layout/Tab.ts
@@ -9,6 +9,7 @@ import {unicode2Emoji} from "../emoji";
import {fetchPost} from "../util/fetch";
import {showTooltip} from "../dialog/tooltip";
import {isTouchDevice} from "../util/functions";
+import {layoutToJSON} from "./util";
export class Tab {
public parent: Wnd;
@@ -76,6 +77,9 @@ export class Tab {
if (tabElement) {
event.dataTransfer.setData("text/html", tabElement.outerHTML);
event.dataTransfer.setData(Constants.SIYUAN_DROP_TAB, this.id);
+ const modeJSON = {}
+ layoutToJSON(this, modeJSON)
+ event.dataTransfer.setData(Constants.SIYUAN_DROP_TABTOWINDOW, JSON.stringify(modeJSON));
event.dataTransfer.dropEffect = "move";
tabElement.style.opacity = "0.1";
window.siyuan.dragElement = this.headElement;
diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts
index d6a62f6666..261ea654ee 100644
--- a/app/src/layout/Wnd.ts
+++ b/app/src/layout/Wnd.ts
@@ -2,7 +2,7 @@ import {Layout} from "./index";
import {genUUID} from "../util/genID";
import {
getInstanceById,
- getWndByLayout,
+ getWndByLayout, JSONToCenter,
newCenterEmptyTab,
resizeTabs,
setPanelFocus,
@@ -297,7 +297,11 @@ export class Wnd {
const targetWndElement = event.target.parentElement.parentElement;
const targetWnd = getInstanceById(targetWndElement.getAttribute("data-id")) as Wnd;
const tabId = event.dataTransfer.getData(Constants.SIYUAN_DROP_TAB);
- const oldTab = getInstanceById(tabId) as Tab;
+ let oldTab = getInstanceById(tabId) as Tab;
+ if (isWindow() && !oldTab) { // 从主窗口拖拽到页签新窗口
+ JSONToCenter(JSON.parse(event.dataTransfer.getData(Constants.SIYUAN_DROP_TABTOWINDOW)), this);
+ oldTab = this.children[this.children.length - 1];
+ }
if (oldTab.model instanceof Asset) {
// https://github.com/siyuan-note/siyuan/issues/6890
const pdfViewerElement = oldTab.model.element.querySelector("#viewerContainer");
@@ -636,6 +640,9 @@ export class Wnd {
}
});
}
+ /// #if !BROWSER
+ setTabPosition();
+ /// #endif
return;
}
if (item.headElement) {