Skip to content

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

:bug: Keep document tab drops in the target window https://github.com/siyuan-note/siyuan/issues/19169

Daniel89c09154f346
diff --git a/app/src/editor/openFileWindow.test.ts b/app/src/editor/openFileWindow.test.ts
new file mode 100644
index 0000000000..9a37e4e6eb
--- /dev/null
+++ b/app/src/editor/openFileWindow.test.ts
@@ -0,0 +1,24 @@
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {shouldCheckOtherWindows} from "./openFileWindow";
+
+describe("cross-window file opening", () => {
+ it("checks other windows for regular file opening", () => {
+ assert.equal(shouldCheckOtherWindows({}), true);
+ });
+
+ it("keeps the existing split-position behavior", () => {
+ assert.equal(shouldCheckOtherWindows({position: "right"}), false);
+ assert.equal(shouldCheckOtherWindows({position: "bottom"}), false);
+ assert.equal(shouldCheckOtherWindows({position: "right", assetPath: "assets/test.pdf"}), true);
+ });
+
+ it("stays in the target window when explicitly requested", () => {
+ assert.equal(shouldCheckOtherWindows({forceCurrentWindow: true}), false);
+ assert.equal(shouldCheckOtherWindows({
+ position: "right",
+ assetPath: "assets/test.pdf",
+ forceCurrentWindow: true,
+ }), false);
+ });
+});
diff --git a/app/src/editor/openFileWindow.ts b/app/src/editor/openFileWindow.ts
new file mode 100644
index 0000000000..f5ac008879
--- /dev/null
+++ b/app/src/editor/openFileWindow.ts
@@ -0,0 +1,8 @@
+export const shouldCheckOtherWindows = (options: {
+ position?: string,
+ assetPath?: string,
+ forceCurrentWindow?: boolean,
+}) => {
+ return !options.forceCurrentWindow &&
+ (!options.position || (options.position === "right" && Boolean(options.assetPath)));
+};
diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index 79eb0a7748..7c36ad6d41 100644
--- a/app/src/editor/util.ts
+++ b/app/src/editor/util.ts
@@ -38,6 +38,7 @@ import {isBrowserRenderableImagePath} from "../util/imageURL";
import {forEachPluginSubscriber} from "../plugin/EventBusCore";
import {getHostCapabilities} from "../util/hostCapabilities";
import {revealTabsForTarget} from "../protyle/render/tabsRender";
+import {shouldCheckOtherWindows} from "./openFileWindow";
const isSameCustomTab = (type: string, data: any, options: IOpenFileOptions) => {
if (!options.custom || (options.custom.id && options.custom.id !== type)) {
@@ -60,6 +61,7 @@ export const openFileById = async (options: {
zoomIn?: boolean
removeCurrentTab?: boolean
openNewTab?: boolean
+ forceCurrentWindow?: boolean
keepAVPanel?: boolean
afterOpen?: (model: Model) => void,
scrollPosition?: ScrollLogicalPosition
@@ -99,6 +101,7 @@ export const openFileById = async (options: {
removeCurrentTab: options.removeCurrentTab,
afterOpen: options.afterOpen,
openNewTab: options.openNewTab,
+ forceCurrentWindow: options.forceCurrentWindow,
keepAVPanel: options.keepAVPanel,
scrollPosition: options.scrollPosition,
});
@@ -250,7 +253,7 @@ export const openFile = async (options: IOpenFileOptions) => {
/// #if !BROWSER
// https://github.com/siyuan-note/siyuan/issues/7491
- if (!options.position || (options.position === "right" && options.assetPath)) {
+ if (shouldCheckOtherWindows(options)) {
let hasMatch = false;
const optionsClone: IObject = {};
Object.keys(options).forEach((key: keyof IOpenFileOptions) => {
diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts
index 76698624aa..17f5c9f65c 100644
--- a/app/src/layout/Wnd.ts
+++ b/app/src/layout/Wnd.ts
@@ -420,7 +420,8 @@ export class Wnd {
openFileById({
app,
id: item,
- action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
+ action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
+ forceCurrentWindow: true,
});
}
});
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 6c3a7c8914..78203d3a1c 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -967,6 +967,7 @@ interface IOpenFileOptions {
zoomIn?: boolean // 是否缩放
removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签
openNewTab?: boolean // 使用新页签打开
+ forceCurrentWindow?: boolean // 仅在当前桌面窗口中打开
keepAVPanel?: boolean // 打开时保留数据库面板
afterOpen?: (model?: import("../layout/Model").Model) => void // 打开后回调
}