diff --git a/src/client/clues/windows/collect.tsx b/src/client/clues/windows/collect.tsx index dfa8c574..57fb0617 100644 --- a/src/client/clues/windows/collect.tsx +++ b/src/client/clues/windows/collect.tsx @@ -156,6 +156,7 @@ export function openClueCollectionWindow( const guard: ClueCollectGuard = { busy: false } const handle = options.windows.open({ id: collectWindowId(options.workspaceId, options.targets), + surface: 'sidebar', title: t('clueBrowserAddToPack'), size: 'compact', bodyLayout: 'fill', diff --git a/src/client/clues/windows/create-pack.tsx b/src/client/clues/windows/create-pack.tsx index 05a5b73d..eef69a46 100644 --- a/src/client/clues/windows/create-pack.tsx +++ b/src/client/clues/windows/create-pack.tsx @@ -69,6 +69,7 @@ export function openCreatePackWindow(options: OpenCreatePackWindowOptions): Wind const guard: CreatePackGuard = { busy: false } const handle = options.windows.open({ id: createPackWindowId(options.workspaceId), + surface: 'sidebar', title: title(), size: 'compact', bodyLayout: 'fill', diff --git a/src/client/clues/windows/detail.tsx b/src/client/clues/windows/detail.tsx index 59074be0..d73107f6 100644 --- a/src/client/clues/windows/detail.tsx +++ b/src/client/clues/windows/detail.tsx @@ -1625,6 +1625,7 @@ export function openClueDetailWindow(options: ClueDetailWindowOptions): WindowHa const handle = windows.open({ id, ...(options.sessionId === undefined ? {} : { sessionId: options.sessionId }), + surface: 'sidebar', title: controller.initialTitle, size: 'document', bodyLayout: 'fill', diff --git a/src/client/clues/windows/pack.tsx b/src/client/clues/windows/pack.tsx index f6da3371..49dfae2c 100644 --- a/src/client/clues/windows/pack.tsx +++ b/src/client/clues/windows/pack.tsx @@ -201,6 +201,7 @@ export function openPackManagementWindow(options: PackManagementOptions): Window dirty ? `${options.pack.name} · ${t('cluePackUnsaved')}` : options.pack.name const handle: WindowHandle = options.windows.open({ id: packWindowId(options.pack.id), + surface: 'sidebar', title: titleFor(false), size: 'collection', content: , diff --git a/src/client/clues/windows/settings.tsx b/src/client/clues/windows/settings.tsx index f74a1411..618ba558 100644 --- a/src/client/clues/windows/settings.tsx +++ b/src/client/clues/windows/settings.tsx @@ -38,6 +38,7 @@ export function openClueSettingsWindow(options: OpenClueSettingsWindowOptions): openClueSettings({ group }) return options.windows.open({ id: CLUE_SETTINGS_WINDOW_ID, + surface: 'sidebar', title: t('clueSettingsWindowTitle'), size: 'collection', content: createElement(SideCardSection, { diff --git a/src/client/clues/windows/share.tsx b/src/client/clues/windows/share.tsx index 91827d32..b851d4a9 100644 --- a/src/client/clues/windows/share.tsx +++ b/src/client/clues/windows/share.tsx @@ -84,6 +84,7 @@ function requestShareWindow(request: ShareWindowRequest): void { export function openShareWindow(options: OpenShareWindowOptions): WindowHandle { const handle = options.windows.open({ id: CLUE_SHARE_WINDOW_ID, + surface: 'sidebar', title: t('clueShareTitle'), size: 'collection', bodyLayout: 'fill', diff --git a/src/client/clues/windows/source-config.tsx b/src/client/clues/windows/source-config.tsx index fc8d8207..2c5fbdf5 100644 --- a/src/client/clues/windows/source-config.tsx +++ b/src/client/clues/windows/source-config.tsx @@ -20,6 +20,7 @@ export function openClueSourceConfigWindow(options: { const name = sourceDisplayName(source, options.display) return options.windows.open({ id: `clue-source:${source.sourceId}`, + surface: 'sidebar', title: t('clueConfigTitle', { source: name }), size: 'collection', bodyLayout: 'fill', diff --git a/src/client/windows/host.ts b/src/client/windows/host.ts index 8d6dbf9a..df20ce3f 100644 --- a/src/client/windows/host.ts +++ b/src/client/windows/host.ts @@ -428,7 +428,7 @@ export function createWindowHost(options: WindowHostOptions = {}): WindowHostCon } record.handle = createHandle(record) records = [...records, record] - notify() + if (options.surface !== 'sidebar' || !setSurface(record, 'sidebar')) notify() return record.handle } diff --git a/src/client/windows/types.ts b/src/client/windows/types.ts index 593a5a11..c806f5ac 100644 --- a/src/client/windows/types.ts +++ b/src/client/windows/types.ts @@ -140,6 +140,12 @@ export interface WindowOpenOptions { bodyLayout?: WindowBodyLayout /** Where the window first appears; omitted = centred. */ anchor?: HTMLElement | null + /** + * Where a NEW window first appears; defaults to 'floating'. 'sidebar' docks it + * as a right-sidebar tab when the native sidebar and a session are available, + * and floats it otherwise. Re-opening a live id never changes its surface. + */ + surface?: 'floating' | 'sidebar' /** Explicit initial pixel size, overriding the preset target (still clamped). */ initialSize?: WindowSize /** Resize floor; defaults to 320×240. */ diff --git a/tests/window-surfaces.spec.tsx b/tests/window-surfaces.spec.tsx index aabd97db..2b7fefbd 100644 --- a/tests/window-surfaces.spec.tsx +++ b/tests/window-surfaces.spec.tsx @@ -173,3 +173,25 @@ it('restores the native destination while an async close decision still needs th expect(open).toHaveBeenCalledTimes(2) expect(host.getSnapshot().windows).toHaveLength(1) }) + +it('opens a surface:sidebar window docked, floats it without a sidebar or session, and never re-docks a live id', () => { + const open = vi.fn() + host = createWindowHost({ sessionId: () => 'original' }) + const unfloated = host.open({ id: 'early', title: 'Early', content: 'x', surface: 'sidebar' }) + expect(host.getSnapshot().windows[0]?.surface).toBe('floating') + unfloated.close() + + host.attachSidebar({ open, focus: () => {}, close: () => {} }) + const handle = host.open({ id: 'docked', title: 'Docked', content: 'x', surface: 'sidebar' }) + expect(open).toHaveBeenCalledWith('docked', 'original', 'Docked') + expect(host.getSnapshot().windows.find(window => window.id === 'docked')?.surface).toBe('sidebar') + + handle.float() + host.open({ id: 'docked', title: 'Docked', content: 'x', surface: 'sidebar' }) + expect(host.getSnapshot().windows.find(window => window.id === 'docked')?.surface).toBe('floating') + expect(open).toHaveBeenCalledTimes(1) + + const defaulted = host.open({ id: 'plain', title: 'Plain', content: 'x' }) + expect(host.getSnapshot().windows.find(window => window.id === 'plain')?.surface).toBe('floating') + defaulted.close() +})