From 5efd58d3af8cf3f56f54e8247f9764cb02e24ff0 Mon Sep 17 00:00:00 2001 From: Vadim Lazuk Date: Tue, 17 Nov 2026 16:37:59 +0300 Subject: [PATCH] fix(workbench): move any project tab to a new window from its own arrow (#3991) The Move Tab to New Window arrow was one bar-level button drawn inside the last tab, above its centre line, and always moved the selected tab. Every project tab now has its own arrow on its right edge, centred and revealed on hover like the close button, and the tab context menu's Move Tab to New Window works on any tab. window_group_detach takes the tab's label and selects it before detaching; without an argument (Find Action) the action still moves the selected tab. Fixes #3954 Co-authored-by: Inf1mum <8135225+Inf1mum@users.noreply.github.com> --- src-tauri/src/commands/window_group.rs | 5 +++-- src/bindings.ts | 2 +- src/features/app/windows.ts | 5 ++++- src/platform/locales/text/en.json | 1 + src/platform/locales/text/zh.json | 1 + src/workbench/WindowGroupTabs.module.css | 11 +++++++++-- src/workbench/WindowGroupTabs.test.tsx | 21 +++++++++++++++++++++ src/workbench/WindowGroupTabs.tsx | 16 ++++++++-------- 8 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src-tauri/src/commands/window_group.rs b/src-tauri/src/commands/window_group.rs index 7546db05a..18626432c 100644 --- a/src-tauri/src/commands/window_group.rs +++ b/src-tauri/src/commands/window_group.rs @@ -29,8 +29,9 @@ pub async fn window_group_select(window: WebviewWindow, label: String) -> IdeRes #[desktop_command(trust = always)] #[tauri::command] #[specta::specta] -pub async fn window_group_detach(window: WebviewWindow) -> IdeResult<()> { - groups::detach(window.app_handle(), window.label())?; +pub async fn window_group_detach(window: WebviewWindow, label: String) -> IdeResult<()> { + groups::select(window.app_handle(), window.label(), &label)?; + groups::detach(window.app_handle(), &label)?; groups::persist(window.app_handle()).await } diff --git a/src/bindings.ts b/src/bindings.ts index b7f81c6c4..aa69dea86 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -1812,7 +1812,7 @@ export const commands = { /** Closes several project tabs one by one (each asks about its own unsaved changes), then selects `keep`. */ windowGroupCloseTabs: (keep: string, labels: string[]) => typedError(__TAURI_INVOKE("window_group_close_tabs", { keep, labels })), windowGroupCurrent: () => typedError(__TAURI_INVOKE("window_group_current")), - windowGroupDetach: () => typedError(__TAURI_INVOKE("window_group_detach")), + windowGroupDetach: (label: string) => typedError(__TAURI_INVOKE("window_group_detach", { label })), windowGroupMerge: () => typedError(__TAURI_INVOKE("window_group_merge")), windowGroupReorder: (labels: string[]) => typedError(__TAURI_INVOKE("window_group_reorder", { labels })), windowGroupRestore: () => typedError(__TAURI_INVOKE("window_group_restore")), diff --git a/src/features/app/windows.ts b/src/features/app/windows.ts index 067be432c..eff7843c8 100644 --- a/src/features/app/windows.ts +++ b/src/features/app/windows.ts @@ -406,7 +406,10 @@ export function windowActions(): Action[] { title: "Move Tab to New Window", category: t("app.category.window"), when: "windowGrouped", - run: () => call(commands.windowGroupDetach()), + run: async ({ arg }) => { + const label = typeof arg === "string" ? arg : useWindowGroup.getState().tabs.find((tab) => tab.current)?.label; + if (label) await call(commands.windowGroupDetach(label)); + }, }, { id: "window.selectTab", diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 332881154..c9e65778b 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -2138,6 +2138,7 @@ "No classes to move to": "No classes to move to", "Move {name} to a new file": "Move {name} to a new file", "Move {name} to another class": "Move {name} to another class", + "Move {name} to New Window": "Move {name} to New Window", "(default package)": "(default package)", "Field": "Field", "Move": "Move", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 5b557aabc..899c651fb 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -8520,6 +8520,7 @@ "No classes to move to": "没有可移动到的类", "Move {name} to a new file": "将 {name} 移动到新文件", "Move {name} to another class": "将 {name} 移动到其他类", + "Move {name} to New Window": "将 {name} 移到新窗口", "(default package)": "(默认包)", "Field": "字段", "Extract Interface…": "提取接口…", diff --git a/src/workbench/WindowGroupTabs.module.css b/src/workbench/WindowGroupTabs.module.css index 396ebee0d..49b234c94 100644 --- a/src/workbench/WindowGroupTabs.module.css +++ b/src/workbench/WindowGroupTabs.module.css @@ -86,8 +86,15 @@ pointer-events: none; } +/* The per-tab detach button mirrors .close on the right edge, centred like it by the row. */ .detach { position: absolute; - right: var(--stripe-outer-padding); - top: 0; + right: 6px; + width: 22px; + height: 22px; + opacity: 0; +} +.item:hover .detach, +.item:focus-within .detach { + opacity: 1; } diff --git a/src/workbench/WindowGroupTabs.test.tsx b/src/workbench/WindowGroupTabs.test.tsx index 4f83e5cfd..5e7803e96 100644 --- a/src/workbench/WindowGroupTabs.test.tsx +++ b/src/workbench/WindowGroupTabs.test.tsx @@ -64,3 +64,24 @@ it("offers closing the other tabs and those on either side of the clicked tab", expect(executeAction).toHaveBeenLastCalledWith("window.closeTabsToLeft", "project-1"); expect(menuFor("Docs")("Close Tabs to the Right").disabled).toBe(true); }); + +it("moves any tab to a new window from its own arrow, without selecting it first", () => { + render(); + fireEvent.click(screen.getByRole("button", { name: "Move Backend to New Window" })); + expect(executeAction).toHaveBeenLastCalledWith("window.detachTab", "project-1"); + expect(executeAction).not.toHaveBeenCalledWith("window.selectTab", "project-1"); +}); + +it("offers Move Tab to New Window for every tab in its context menu", () => { + render(); + fireEvent.contextMenu(screen.getByRole("tab", { name: "Backend" })); + const item = useContextMenuStore + .getState() + .menu!.items.find((i) => "label" in i && i.label === "Move Tab to New Window") as { + disabled?: boolean; + run?: () => unknown; + }; + expect(item.disabled).toBeUndefined(); + void item.run?.(); + expect(executeAction).toHaveBeenLastCalledWith("window.detachTab", "project-1"); +}); diff --git a/src/workbench/WindowGroupTabs.tsx b/src/workbench/WindowGroupTabs.tsx index 8327c2efa..74698f2ba 100644 --- a/src/workbench/WindowGroupTabs.tsx +++ b/src/workbench/WindowGroupTabs.tsx @@ -102,8 +102,7 @@ export function WindowGroupTabs() { showContextMenu(e, [ { label: "Move Tab to New Window", - disabled: !tab.current, - run: () => executeAction("window.detachTab"), + run: () => executeAction("window.detachTab", tab.label), }, { kind: "separator" }, { @@ -156,15 +155,16 @@ export function WindowGroupTabs() { title={tx`Close ${tab.name}`} onClick={() => run(executeAction("window.closeTab", tab.label))} /> + run(executeAction("window.detachTab", tab.label))} + /> ))} - ); }