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/15416

Vanessa1297df9fb85a
diff --git a/app/src/boot/globalEvent/command/global.ts b/app/src/boot/globalEvent/command/global.ts
index 572819018b..2bc198dea3 100644
--- a/app/src/boot/globalEvent/command/global.ts
+++ b/app/src/boot/globalEvent/command/global.ts
@@ -15,7 +15,7 @@ import {isWindow} from "../../../util/functions";
import {openRecentDocs} from "../../../business/openRecentDocs";
import {openSearch} from "../../../search/spread";
import {goBack, goForward} from "../../../util/backForward";
-import {getAllTabs, getAllWnds} from "../../../layout/getAll";
+import {getAllTabs} from "../../../layout/getAll";
import {getInstanceById} from "../../../layout/util";
import {
closeTabByType,
@@ -38,8 +38,7 @@ import {lockScreen} from "../../../dialog/processSystem";
import {newFile} from "../../../util/newFile";
import {openCard} from "../../../card/openCard";
import {syncGuide} from "../../../sync/syncGuide";
-import {Wnd} from "../../../layout/Wnd";
-import {unsplitWnd} from "../../../menus/tab";
+import {unsplitCurrentWnd, unsplitWnd} from "../../../menus/tab";
import {openFile} from "../../../editor/util";
import {fetchPost} from "../../../util/fetch";
import {sanitizeClosedTabs, setStorageVal} from "../../../protyle/util/compatibility";
@@ -317,24 +316,13 @@ export const globalCommand = (command: string, app: App) => {
return true;
}
if (command === "unsplitAll") {
- unsplitWnd(window.siyuan.layout.centerLayout, window.siyuan.layout.centerLayout, false);
+ unsplitWnd(window.siyuan.layout.centerLayout, window.siyuan.layout.centerLayout);
return true;
}
if (command === "unsplit") {
const tab = getActiveTab(false);
if (tab) {
- let wndsTemp: Wnd[] = [];
- let layout = tab.parent.parent;
- while (layout.id !== window.siyuan.layout.centerLayout.id) {
- wndsTemp = [];
- getAllWnds(layout, wndsTemp);
- if (wndsTemp.length > 1) {
- break;
- } else {
- layout = layout.parent;
- }
- }
- unsplitWnd(tab.parent.parent.children[0], layout, true);
+ unsplitCurrentWnd(tab.parent);
resizeTabs();
}
return true;
diff --git a/app/src/menus/tab.ts b/app/src/menus/tab.ts
index 379aa1fdd8..b34a6b8514 100644
--- a/app/src/menus/tab.ts
+++ b/app/src/menus/tab.ts
@@ -145,7 +145,7 @@ const splitSubMenu = (app: App, tab: Tab) => {
}
});
}
- let wndsTemp: Wnd[] = [];
+ const wndsTemp: Wnd[] = [];
getAllWnds(window.siyuan.layout.centerLayout, wndsTemp);
if (wndsTemp.length > 1) {
subMenus.push({
@@ -153,17 +153,7 @@ const splitSubMenu = (app: App, tab: Tab) => {
label: window.siyuan.languages.unsplit,
accelerator: window.siyuan.config.keymap.general.unsplit.custom,
click: () => {
- let layout = tab.parent.parent;
- while (layout.id !== window.siyuan.layout.centerLayout.id) {
- wndsTemp = [];
- getAllWnds(layout, wndsTemp);
- if (wndsTemp.length > 1) {
- break;
- } else {
- layout = layout.parent;
- }
- }
- unsplitWnd(tab.parent.parent.children[0], layout, true);
+ unsplitCurrentWnd(tab.parent);
resizeTabs();
}
});
@@ -172,7 +162,7 @@ const splitSubMenu = (app: App, tab: Tab) => {
label: window.siyuan.languages.unsplitAll,
accelerator: window.siyuan.config.keymap.general.unsplitAll.custom,
click: () => {
- unsplitWnd(window.siyuan.layout.centerLayout, window.siyuan.layout.centerLayout, false);
+ unsplitWnd(window.siyuan.layout.centerLayout, window.siyuan.layout.centerLayout);
resizeTabs();
}
});
@@ -253,15 +243,33 @@ export const initTabMenu = (app: App, tab: Tab) => {
return window.siyuan.menus.menu;
};
-export const unsplitWnd = (target: Wnd | Layout, layout: Layout, onlyWnd: boolean) => {
+export const unsplitCurrentWnd = (wnd: Wnd) => {
+ const wnds: Wnd[] = [];
+ getAllWnds(window.siyuan.layout.centerLayout, wnds);
+ const index = wnds.indexOf(wnd);
+ if (index === -1) {
+ return;
+ }
+ const target = wnds[index - 1] || wnds[index + 1];
+ if (!target) {
+ return;
+ }
+ while (wnd.children.length > 0) {
+ const tab = wnd.children[0];
+ target.headersElement.append(tab.headElement);
+ target.moveTab(tab);
+ }
+};
+
+export const unsplitWnd = (target: Wnd | Layout, layout: Layout) => {
let wnd: Wnd = target as Wnd;
while (wnd instanceof Layout) {
wnd = wnd.children[0] as Wnd;
}
for (let i = 0; i < layout.children.length; i++) {
const item = layout.children[i];
- if (item instanceof Layout && !onlyWnd) {
- unsplitWnd(wnd, item, onlyWnd);
+ if (item instanceof Layout) {
+ unsplitWnd(wnd, item);
} else if (item instanceof Wnd && item.id !== wnd.id && item.children.length > 0) {
for (let j = 0; j < item.children.length; j++) {
const tab = item.children[j];