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>
This commit is contained in:
Vadim Lazuk
2026-11-17 21:37:59 +08:00
committed by GitHub
co-authored by Inf1mum
parent d250b351bb
commit 5efd58d3af
8 changed files with 48 additions and 14 deletions
+3 -2
View File
@@ -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
}
+1 -1
View File
@@ -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<null, IdeError>(__TAURI_INVOKE("window_group_close_tabs", { keep, labels })),
windowGroupCurrent: () => typedError<WindowTab[], IdeError>(__TAURI_INVOKE("window_group_current")),
windowGroupDetach: () => typedError<null, IdeError>(__TAURI_INVOKE("window_group_detach")),
windowGroupDetach: (label: string) => typedError<null, IdeError>(__TAURI_INVOKE("window_group_detach", { label })),
windowGroupMerge: () => typedError<null, IdeError>(__TAURI_INVOKE("window_group_merge")),
windowGroupReorder: (labels: string[]) => typedError<null, IdeError>(__TAURI_INVOKE("window_group_reorder", { labels })),
windowGroupRestore: () => typedError<null, IdeError>(__TAURI_INVOKE("window_group_restore")),
+4 -1
View File
@@ -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",
+1
View File
@@ -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",
+1
View File
@@ -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…": "提取接口…",
+9 -2
View File
@@ -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;
}
+21
View File
@@ -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(<WindowGroupTabs />);
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(<WindowGroupTabs />);
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");
});
+8 -8
View File
@@ -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))}
/>
<IconButton
icon="external-link"
size="small"
className={styles.detach}
title={tx`Move ${tab.name} to New Window`}
onClick={() => run(executeAction("window.detachTab", tab.label))}
/>
</div>
))}
</div>
<IconButton
className={styles.detach}
icon="external-link"
title="Move Tab to New Window"
action="window.detachTab"
/>
</div>
);
}