fix(native): offer one "Files" row in the new-tab list

The editor type's page identity IS the `files` kind takeover (same
explorer, same title), so the guide/new-tab list showed two identical
"Files" entries — observed on a real profile after the takeover landed.
The editor type now contributes no guide entry of its own; it stays
registered as the file RESOURCE viewer. Covered by the registration
lifecycle test (editor: no guide, files takeover: guide).
This commit is contained in:
Menghuan1918
2026-09-09 15:06:31 +08:00
parent 4da2b43610
commit b56ceec41d
2 changed files with 14 additions and 4 deletions
+5 -1
View File
@@ -160,7 +160,11 @@ export function registerNativeSurface(deps: NativeSurfaceDeps): () => void {
// A resource tab is titled by the file it shows; a page tab keeps the
// descriptor's own title.
title: (address: string) => (isEditor ? fileTitleOf(address) ?? titleOf(descriptor) : titleOf(descriptor)),
...(descriptor.hidden === true
// No guide entry for the editor: its page identity is the `files`
// kind takeover below (same view, same title), so listing both would
// offer the reader two identical "Files" rows. The type itself stays
// registered as the file RESOURCE viewer.
...(descriptor.hidden === true || isEditor
? {}
: {
guide: [{
+9 -3
View File
@@ -166,12 +166,12 @@ describe('registerNativeSurface lifecycle (service-driven registration)', () =>
service.registerTab({ id: 'editor', title: 'Files', component: () => null })
const records = createNativeTabRecords()
const registered: Array<{ id: string; kind: string; title: (address: string) => string }> = []
const registered: Array<{ id: string; kind: string; title: (address: string) => string; guide: unknown }> = []
const slotKeys: string[] = []
// The registry is ABSENT while the slot callback fires and appears later
// (that ordering is the regression): a holder keeps the timing honest
// without a reassigned binding.
const registry: { current: { register: (definition: { id: string; kind: string; title: (address: string) => string }) => () => void } | undefined } = { current: undefined }
const registry: { current: { register: (definition: { id: string; kind: string; title: (address: string) => string; guide?: unknown }) => () => void } | undefined } = { current: undefined }
let runInjected: (() => void) | undefined
const ctx = {
@@ -200,7 +200,7 @@ describe('registerNativeSurface lifecycle (service-driven registration)', () =>
// …and everything registers once it appears.
registry.current = {
register: (definition) => {
registered.push({ id: definition.id, kind: definition.kind, title: definition.title })
registered.push({ id: definition.id, kind: definition.kind, title: definition.title, guide: definition.guide })
return () => {}
},
}
@@ -217,6 +217,12 @@ describe('registerNativeSurface lifecycle (service-driven registration)', () =>
expect(editorType?.title('dsh-resource://file/session/s1/src/main.ts')).toBe('main.ts')
expect(editorType?.title('dsh-resource://file/absolute/work/pkg/a/b.txt')).toBe('b.txt')
expect(editorType?.title('sidebar://editor')).toBe('Files')
// The new-tab/guide list must offer ONE "Files" row: the `files` kind
// takeover draws the same explorer the editor page would, so the editor
// type contributes no guide entry of its own.
expect(editorType?.guide).toBeUndefined()
const filesType = registered.find(entry => entry.kind === 'files')
expect(filesType?.guide).toBeDefined()
dispose()
})