diff --git a/apps/desktop/src/renderer/features/tabs/TabBar.tsx b/apps/desktop/src/renderer/features/tabs/TabBar.tsx index d369e3d..570cbe5 100644 --- a/apps/desktop/src/renderer/features/tabs/TabBar.tsx +++ b/apps/desktop/src/renderer/features/tabs/TabBar.tsx @@ -7,10 +7,12 @@ export function TabBar() { const { openDoc, currentPath } = useStore(); const [hoveredTab, setHoveredTab] = useState(null); - // 当 activeId 变化,加载对应标签的文档 + // 当 activeId 变化,加载对应标签的文档;标签全部关闭时清空编辑器 + const resetEditor = useStore(s => s.resetEditor); useEffect(() => { const tab = tabs.find(t => t.id === activeId); if (tab && tab.path !== currentPath) openDoc(tab.path); + else if (!activeId && currentPath) resetEditor(); }, [activeId]); if (tabs.length === 0) return null; diff --git a/apps/desktop/tests/e2e/button-all.spec.ts b/apps/desktop/tests/e2e/button-all.spec.ts index 706567b..1682087 100644 --- a/apps/desktop/tests/e2e/button-all.spec.ts +++ b/apps/desktop/tests/e2e/button-all.spec.ts @@ -321,3 +321,21 @@ test('TabBar: 固定+关闭可用', async () => { await expect(a.page.getByTestId('tabbar').getByText('Tab2', { exact: true })).toHaveCount(0, { timeout: 3000 }); await a.app.close(); }); + +test('TabBar: 关闭全部标签后编辑器应显示空状态', async () => { + const a = await launch(nodePath.join(os.tmpdir(), 'hn-close-all-' + Date.now())); + await setupVault(a, [{ name: 'CloseAllTest', body: '# 关闭全部测试\n正文内容' }]); + // 打开文档 + await a.page.getByTestId('filetree').getByText('CloseAllTest', { exact: true }).click(); + await expect(a.page.getByTestId('tabbar').getByText('CloseAllTest', { exact: true })).toBeVisible(); + // 编辑器应显示文档内容 + await expect(a.page.locator('.ProseMirror')).toContainText('关闭全部测试'); + // 关闭标签页(span 文本 x) + const tab = a.page.getByTestId('tabbar').locator('div').filter({ hasText: 'CloseAllTest' }).first(); + await tab.locator('span').filter({ hasText: 'x' }).click(); + await a.page.waitForTimeout(500); + // 标签栏为空 → 当前文档应重置,编辑器显示空状态提示 + expect(await a.page.evaluate(() => (globalThis as any).__STORE__?.getState?.().currentPath)).toBeNull(); + await expect(a.page.getByText('从左侧选择一篇笔记')).toBeVisible({ timeout: 5000 }); + await a.app.close(); +});