fix(vscode): match section navigation order

This commit is contained in:
marius-kilocode
2026-08-04 11:07:15 +02:00
parent d9d3568f3f
commit c8f86d8f91
2 changed files with 34 additions and 4 deletions
@@ -457,6 +457,32 @@ describe("buildProjectNavOrder", () => {
])
})
it("matches raw ungrouped order when sections are present", () => {
const order = buildProjectNavOrder([
project({
id: "A",
expanded: true,
worktrees: [
{ id: "aw1", groupId: "g" },
{ id: "aw2" },
{ id: "aw3", groupId: "g" },
{ id: "aw4", sectionId: "s1" },
],
worktreeOrder: ["aw1", "aw2", "aw3", "s1", "aw4"],
sections: [{ id: "s1", collapsed: false }],
unassigned: [],
}),
])
expect(order.map((e) => e.id)).toEqual([
localNavId("A"),
worktreeNavId("A", "aw1"),
worktreeNavId("A", "aw2"),
worktreeNavId("A", "aw3"),
worktreeNavId("A", "aw4"),
])
})
it("excludes unassigned sessions when the sessions section is collapsed", () => {
const order = buildProjectNavOrder([
project({
@@ -191,13 +191,17 @@ export function buildProjectNavOrder(projects: ProjectNavInput[]): NavEntry[] {
order.push({ id: localNavId(pid), target: { projectId: pid, kind: "local" } })
const worktrees = sortWorktrees(p.worktrees, p.worktreeOrder ?? [])
const rank = new Map((p.worktreeOrder ?? []).map((id, index) => [id, index] as const))
const ungrouped = worktrees.filter((w) => !w.sectionId)
if (p.sections.length > 0) {
ungrouped.sort(
(a, b) => (rank.get(a.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.id) ?? Number.MAX_SAFE_INTEGER),
)
}
const secs = [...p.sections].sort(
(a, b) => (rank.get(a.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.id) ?? Number.MAX_SAFE_INTEGER),
)
for (const w of worktrees) {
if (!w.sectionId) {
order.push({ id: worktreeNavId(pid, w.id), target: { projectId: pid, kind: "worktree", worktreeId: w.id } })
}
for (const w of ungrouped) {
order.push({ id: worktreeNavId(pid, w.id), target: { projectId: pid, kind: "worktree", worktreeId: w.id } })
}
for (const sec of secs) {
if (sec.collapsed) continue