fix(session): bind new sessions to selected project (#1708)

* fix(session): bind new sessions to selected project

Fix #1521: openNewSessionDraft() always used currentDirectory even when
the user selected a different project. Now prefers the selected project's
path when no explicit directory is provided.

* test(session): add unit test for openNewSessionDraft project binding

---------

Co-authored-by: Leonid Skorobogatyy <bash@opencode.itc.local>
Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
bashrusakh
2026-06-23 22:14:33 +03:00
committed by GitHub
co-authored by Leonid Skorobogatyy Bohdan Triapitsyn
parent 83256ba924
commit 5f3ef320d2
2 changed files with 49 additions and 0 deletions
+3
View File
@@ -626,6 +626,7 @@ 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
})()
@@ -633,6 +634,8 @@ 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)