refactor: 完全解耦内置 tab — dedupe 归 service,图标归 descriptor

- state.openTab 简化为 '添加到 pane + id dedupe',移除 isSingle/editor-path/diff-id 三分支
  (dedupe 策略归 service.openTab 通过 descriptor.dedupeKey 统一)
- intercept.tsx openSidebarFile 改走 service.openTab(editor descriptor 的 dedupeKey 接管 per-path 去重)
- Sidebar.tsx 两处 subagent 触发(auto-activation + jump-back)改走 service.openTab
- service.openTab seed 加可选 id 字段(editor 需要 path-derived id)
- TabBar.tsx 加 getTabIcon 回调,tab 标签图标查 descriptor.icon 替代 tabTypeIcon
- split-pane.tsx 移除 tabTypeIcon 兜底(buildNewTabOptions 已从 descriptor 填 icon)
- Workbench/NodeView/LeafView 透传 getTabIcon
- tests/unit.spec.ts 更新 openTab 测试(id dedupe 替代 type dedupe)
This commit is contained in:
HuanLinOTO committed 2026-08-11 01:39:20 +08:00
1 parent 291158a3ba
commit e40039ceec
7 files changed
+52 -62

No files matched your search

+3 -3
View File
@@ -126,7 +126,7 @@ export interface BetterSidebarService {
/** Find a file viewer for a path (priority desc → detect → exts). */
matchFileViewer(path: string, head?: Uint8Array): FileViewerDescriptor | undefined
/** Open a tab (used by external tabs and the + menu). */
openTab(seed: { type: string; title: string; path?: string; diff?: SidebarTab['diff'] }): void
openTab(seed: { type: string; title: string; path?: string; diff?: SidebarTab['diff']; id?: string }): void
/** Close a tab by id. */
closeTab(tabId: string): void
/** Subscribe to registry changes (register/dispose). */
@@ -216,7 +216,7 @@ export function createBetterSidebarService(store: SidebarStore): BetterSidebarSe
return undefined
}
const openTab = (seed: { type: string; title: string; path?: string; diff?: SidebarTab['diff'] }): void => {
const openTab = (seed: { type: string; title: string; path?: string; diff?: SidebarTab['diff']; id?: string }): void => {
store.reduce((state) => {
const descriptor = tabs.get(seed.type)
if (descriptor === undefined) return state
@@ -228,7 +228,7 @@ export function createBetterSidebarService(store: SidebarStore): BetterSidebarSe
return result.patch !== undefined ? { ...next, ...result.patch } : next
}
const tab: SidebarTab = {
id: seed.type,
id: seed.id ?? seed.type,
type: seed.type,
title: typeof descriptor.title === 'function' ? descriptor.title() : descriptor.title,
...(seed.path !== undefined ? { path: seed.path } : {}),