fix(session): prefer current directory for implicit drafts
This commit is contained in:
@@ -4,6 +4,7 @@ import type { Snippet } from '@/types/snippet';
|
||||
import { opencodeClient } from '@/lib/opencode/client';
|
||||
import { runtimeFetch } from '@/lib/runtime-fetch';
|
||||
import { useProjectsStore } from '@/stores/useProjectsStore';
|
||||
import { useDirectoryStore } from '@/stores/useDirectoryStore';
|
||||
|
||||
export type SnippetScope = 'global' | 'project';
|
||||
|
||||
@@ -37,10 +38,12 @@ let loadInFlight: Promise<boolean> | null = null;
|
||||
|
||||
const getRequestDirectory = (): string | null => {
|
||||
try {
|
||||
const activeProject = useProjectsStore.getState().getActiveProject?.();
|
||||
if (activeProject?.path?.trim()) return activeProject.path.trim();
|
||||
const currentDirectory = useDirectoryStore.getState().currentDirectory;
|
||||
if (currentDirectory?.trim()) return currentDirectory.trim();
|
||||
const clientDir = opencodeClient.getDirectory();
|
||||
if (clientDir?.trim()) return clientDir.trim();
|
||||
const activeProject = useProjectsStore.getState().getActiveProject?.();
|
||||
if (activeProject?.path?.trim()) return activeProject.path.trim();
|
||||
} catch (error) {
|
||||
console.warn('[SnippetsStore] Error resolving config directory:', error);
|
||||
}
|
||||
|
||||
@@ -246,13 +246,13 @@ describe('openNewSessionDraft project binding', () => {
|
||||
useDirectoryStore.getState().setDirectory(projectB.path, { showOverlay: false });
|
||||
});
|
||||
|
||||
test('binds draft to active project when current directory differs', () => {
|
||||
test('keeps implicit draft on current directory when active project differs', () => {
|
||||
useSessionUIStore.getState().openNewSessionDraft();
|
||||
const draft = useSessionUIStore.getState().newSessionDraft;
|
||||
|
||||
expect(draft.open).toBe(true);
|
||||
expect(draft.selectedProjectId).toBe(projectA.id);
|
||||
expect(draft.directoryOverride).toBe(projectA.path);
|
||||
expect(draft.selectedProjectId).toBe(projectB.id);
|
||||
expect(draft.directoryOverride).toBe(projectB.path);
|
||||
});
|
||||
|
||||
test('respects explicit directoryOverride over active project', () => {
|
||||
|
||||
@@ -626,7 +626,6 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
if (explicitProject || explicitDirectory !== null) {
|
||||
return explicitProject ?? inferredProjectFromDir ?? fallbackProject
|
||||
}
|
||||
if (activeProject) return activeProject
|
||||
if (currentDirectory) return currentDirProject ?? fallbackProject
|
||||
return persistedProjectByDir ?? persistedProjectById ?? fallbackProject
|
||||
})()
|
||||
@@ -634,8 +633,6 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
const directory = (() => {
|
||||
if (explicitDirectory !== null) return explicitDirectory
|
||||
if (explicitProject) return normalizePath(explicitProject.path ?? null)
|
||||
const selectedProjectPath = normalizePath(selectedProject?.path ?? null)
|
||||
if (selectedProjectPath && selectedProjectPath !== currentDirectory) return selectedProjectPath
|
||||
if (currentDirectory) return currentDirectory
|
||||
if (persistedTarget?.directory) return persistedTarget.directory
|
||||
return normalizePath(selectedProject?.path ?? null)
|
||||
|
||||
Reference in New Issue
Block a user