fix(tabs): 关闭全部标签页后编辑器未清空——closeTab 仅清空 tabs/activeId 不清 store.currentPath, 导致 TiptapEditor 仍渲染旧文档. TabBar useEffect 加 resetEditor: 当 activeId 为 null 且 currentPath 非空时调用 store.resetEditor 清空 currentPath/body/meta, 编辑器正确显示空状态提示; 新增 E2E 验证

This commit is contained in:
hunter-dev
2026-08-26 19:21:29 +08:00
parent 34d3fec449
commit b01bdd380a
2 changed files with 21 additions and 1 deletions
@@ -7,10 +7,12 @@ export function TabBar() {
const { openDoc, currentPath } = useStore();
const [hoveredTab, setHoveredTab] = useState<string | null>(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;
+18
View File
@@ -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();
});