Close secondary workspace windows after the last tab

This commit is contained in:
Knotty Wyvern
2026-10-21 15:06:55 -07:00
parent b742d274f1
commit f741389418
4 changed files with 75 additions and 6 deletions
+17
View File
@@ -741,3 +741,20 @@ Native shell, background image, and desktop acceptance remain open.
- Evidence files: RuneStone_Project_Management/.audit/october-{default,onboarding}-{theme}-{width}.png. The packaged plugin also passes its host state check.
- Local overrides: The new onboarding control uses the existing standard button for readable text in both themes.
- Limits: Browser checks use desktop service mocks. Native desktop acceptance remains open.
### UI-039 — Close secondary windows after the last tab
- Type: Rule change
- Date: 2026-10-21
- Status: Implemented for user review
- Decision source: Card 6fcee006-c5a5-4d1b-9605-5d763715b95c.
- New rule: Closing the last tab closes a secondary workspace window. The main window keeps a New tab.
- Reason: Close an empty secondary window when the user finishes its work.
- Scope: Ordinary secondary workspace windows and detached tabs, including documents, plugin views, and empty tabs.
- Shared implementation: Workbench.closeTabs calls the existing window-close handler. Cancel preserves the last tab and unsaved edits.
- Shared tokens: Existing tab controls, icons, focus, and theme tokens. No style or color changes.
- Local overrides: None added.
- Evidence: Type checks and 268 unit tests pass. The tab browser check passes for button, middle-click, shortcut, and Close all.
- Evidence: The browser check also covers mixed tabs, pinned tabs, plugin tabs, and Cancel with unsaved edits.
- Evidence files: .audit/secondary-last-tab-cancel.png and .audit/compact-tabs-{width}-{theme}.png.
- Limits: Desktop calls use browser mocks. Native window closure and active terminal confirmation still need desktop acceptance.
+5 -1
View File
@@ -32,7 +32,11 @@ The active navigation button shows which view occupies the left pane.
Document and plugin tabs share the tab bar. The new-tab button follows the tabs.
Tabs retain their order and pin state when a plugin replaces its current view.
The last closed tab leaves an empty New tab. Sidebar widths and visibility persist across window sessions.
The main window keeps an empty New tab after the last tab closes.
Secondary workspace windows close when the user closes their last document, plugin, browser, or empty tab.
Window closure retains the existing confirmation for unsaved edits and active terminal sessions.
Cancel keeps the last tab and its contents open. See [UI-039](design-decisions.md#ui-039--close-secondary-windows-after-the-last-tab).
Sidebar widths and visibility persist across window sessions.
Opening a different editor does not restore a hidden outline.
Detached tabs contain the tab work area and window controls. They do not mount side panes, a plugin ribbon, or pane switches.
Their layout does not change the main window layout. See [UI-004](design-decisions.md#ui-004--detached-tab-work-area).
+47 -4
View File
@@ -42,12 +42,13 @@ await context.addInitScript(({ pluginCode }) => {
const callbacks = new Map(), listeners = new Map();
let sequence = 0, enabled = true;
const manifest = { schemaVersion: 1, id: "test.tabs", name: "Tab fixtures", author: "Tests", description: "Test editor tabs.", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
const emit = (event, payload) => {
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
const emit = async (event, payload) => {
await Promise.all((listeners.get(event) || []).map(id => callbacks.get(id)?.({ event, id, payload })));
};
window.tabTest = { mounts: {}, disposals: {}, answer: "Cancel", prompts: 0, files };
window.tabTest = { mounts: {}, disposals: {}, answer: "Cancel", prompts: 0, closeRequests: 0, destroys: 0, files };
const label = location.search.includes("secondary") ? "workspace-2" : "main";
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
metadata: { currentWindow: { label }, currentWebview: { label } },
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
unregisterCallback: id => callbacks.delete(id),
invoke: async (command, args = {}) => {
@@ -59,6 +60,12 @@ await context.addInitScript(({ pluginCode }) => {
}
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
if (command === "plugin:window|is_maximized") return false;
if (command === "plugin:window|close") {
window.tabTest.closeRequests++;
await emit("tauri://close-requested");
return;
}
if (command === "plugin:window|destroy") { window.tabTest.destroys++; return; }
if (command.startsWith("plugin:window|")) return;
if (command === "plugins_snapshot") return { root, plugins: [{ manifest, hash: "test", enabled, path: root, error: null, removal: false }] };
if (command === "plugins_load") return pluginCode;
@@ -304,6 +311,42 @@ try {
assert.deepEqual(await order(), ["New tab"]);
assert.deepEqual(errors, []);
console.log("PASS: plugin tabs reorder and close without an open workspace");
for (const close of ["button", "middle", "shortcut", "all", "plugin", "dirty"]) {
await page.goto(`${url}?secondary`);
await tab("New tab").waitFor();
if (close === "plugin") {
await openView("Overview");
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
assert.equal(await page.evaluate(() => window.tabTest.closeRequests), 0);
await page.getByRole("button", { name: "Close Overview", exact: true }).click();
} else if (close === "dirty") {
await openFile("a.md");
await page.locator(".cm-content").fill("Keep these unsaved edits");
await page.keyboard.press("Control+w");
await page.waitForFunction(() => window.tabTest.prompts === 1);
assert.equal(await page.evaluate(() => window.tabTest.destroys), 0);
assert.match(await page.locator(".cm-content").innerText(), /Keep these unsaved edits/);
await mkdir(".audit", { recursive: true });
await page.screenshot({ path: ".audit/secondary-last-tab-cancel.png" });
await page.evaluate(() => window.tabTest.answer = "Ok");
await page.keyboard.press("Control+w");
} else if (close === "button") {
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
} else if (close === "middle") {
await tab("New tab").click({ button: "middle" });
} else if (close === "shortcut") {
await page.keyboard.press("Control+w");
} else {
await openFile("a.md");
await openFile("b.md");
await menu("b.md");
await page.getByRole("menuitem", { name: "Close all", exact: true }).click();
}
await page.waitForFunction(() => window.tabTest.destroys === 1);
assert.equal(await page.evaluate(() => window.tabTest.closeRequests), close === "dirty" ? 2 : 1);
}
assert.deepEqual(errors, []);
console.log("PASS: secondary windows close through the window guard for the last empty, document, or plugin tab; Cancel preserves unsaved edits");
} catch (error) {
await mkdir(".audit", { recursive: true });
await page.screenshot({ path: ".audit/plugin-tab-order-failure.png" });
+6 -1
View File
@@ -504,8 +504,13 @@
for (const target of targets) {
if (documents !== current || switching) break;
const tab = "buffer" in target ? current?.buffers.find(item => item.id === target.buffer.id) : undefined;
if ("buffer" in target && (!tab || (scope !== "one" && tab.pinned))) continue;
if (desktop && getCurrentWindow().label.startsWith("workspace-") && workingTabs.length === 1) {
await getCurrentWindow().close();
break;
}
if ("buffer" in target) {
if (!tab || (scope !== "one" && tab.pinned)) continue;
if (!tab) continue;
const contents = tab.contents;
if (contents !== tab.saved && !await confirm($t("Discard unsaved edits in {name}?", { name: tab.name }), { title: $t("Close document"), kind: "warning" })) break;
if (documents !== current || switching || tab.contents !== contents) break;