Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions scripts/batchCloseConfirmation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';

const viewer = readFileSync(new URL('../src/lib/MarkdownViewer.svelte', import.meta.url), 'utf8');

test('batch tab-close commands use the existing dirty-tab confirmation flow', () => {
assert.match(viewer, /async function closeTabsWithConfirmation\(tabIds: string\[\]\)/);
assert.match(
viewer,
/for \(const tabId of tabIds\) \{\s*if \(!\(await canCloseTab\(tabId\)\)\) return;\s*tabManager\.closeTab\(tabId\);\s*\}/,
);
assert.match(viewer, /menu-tab-close-others[\s\S]*await closeTabsWithConfirmation\(tabsToClose\)/);
assert.match(viewer, /menu-tab-close-right[\s\S]*await closeTabsWithConfirmation\(tabsToClose\)/);
assert.match(viewer, /appWindow\.listen\('menu-tab-close-others', async \(event\)/);
assert.match(viewer, /appWindow\.listen\('menu-tab-close-right', async \(event\)/);
});
15 changes: 11 additions & 4 deletions src/lib/MarkdownViewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,13 @@ import { t } from './utils/i18n.js';
await destroyWindowAfterTabsClosed();
}

async function closeTabsWithConfirmation(tabIds: string[]) {
for (const tabId of tabIds) {
if (!(await canCloseTab(tabId))) return;
tabManager.closeTab(tabId);
}
}

async function destroyWindowAfterTabsClosed() {
if (settings.restoreStateOnReopen) {
await persistWindowState();
Expand Down Expand Up @@ -2940,19 +2947,19 @@ import { t } from './utils/i18n.js';
}),
);
unlisteners.push(
await appWindow.listen('menu-tab-close-others', (event) => {
await appWindow.listen('menu-tab-close-others', async (event) => {
const tabId = event.payload as string;
const tabsToClose = tabManager.tabs.filter((t) => t.id !== tabId).map((t) => t.id);
tabsToClose.forEach((id) => tabManager.closeTab(id));
await closeTabsWithConfirmation(tabsToClose);
}),
);
unlisteners.push(
await appWindow.listen('menu-tab-close-right', (event) => {
await appWindow.listen('menu-tab-close-right', async (event) => {
const tabId = event.payload as string;
const index = tabManager.tabs.findIndex((t) => t.id === tabId);
if (index !== -1) {
const tabsToClose = tabManager.tabs.slice(index + 1).map((t) => t.id);
tabsToClose.forEach((id) => tabManager.closeTab(id));
await closeTabsWithConfirmation(tabsToClose);
}
}),
);
Expand Down
Loading