Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/renderer/src/components/sidebar/WorkspaceKanbanDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,10 @@ function WorkspaceKanbanDrawerContent({
for (const group of boardDragGroups) {
for (const worktreeId of group.worktreeIds) {
const worktree = worktreeById.get(worktreeId)
if (worktree) {
ranks.set(worktreeId, worktree.manualOrder ?? worktree.sortOrder)
// Why: only real manualOrder ranks here — holes get backfilled by the
// ranker, not masked with the mutable sortOrder.
if (worktree?.manualOrder !== undefined) {
ranks.set(worktreeId, worktree.manualOrder)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,14 @@ describe('workspace kanban sidebar drop updates', () => {
})

expect(result.shouldSwitchToManual).toBe(true)
// Why: with no prior manualOrder anywhere, the drop backfills every visible row
// so the manual order is stable (doing-a > todo-a > doing-b) instead of sparse-
// ranking only the dropped row onto the mutable sortOrder.
expect(result.updates.get('todo-a')).toEqual({
workspaceStatus: 'doing',
manualOrder: 1500
manualOrder: 9000
})
expect(result.updates.get('doing-a')).toEqual({ manualOrder: 10_000 })
expect(result.updates.get('doing-b')).toEqual({ manualOrder: 8000 })
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ export function buildWorkspaceKanbanSidebarDropUpdates(args: {
for (const group of args.groups) {
for (const worktreeId of group.worktreeIds) {
const worktree = args.worktreeById.get(worktreeId)
if (worktree) {
ranks.set(worktreeId, worktree.manualOrder ?? worktree.sortOrder)
// Why: only real manualOrder ranks here — holes get backfilled by the ranker,
// not masked with the mutable sortOrder.
if (worktree?.manualOrder !== undefined) {
ranks.set(worktreeId, worktree.manualOrder)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ function buildRankByWorktreeId(
for (const group of groups) {
for (const worktreeId of group.worktreeIds) {
const worktree = worktreeMap.get(worktreeId)
if (worktree) {
rankByWorktreeId.set(worktreeId, worktree.manualOrder ?? worktree.sortOrder)
// Why: only real manualOrder ranks here — a row still lacking one is a hole
// the ranker backfills, rather than masking it with the mutable sortOrder.
if (worktree?.manualOrder !== undefined) {
rankByWorktreeId.set(worktreeId, worktree.manualOrder)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/src/components/sidebar/worktree-manual-order-ranks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ export function buildSparseManualOrderUpdates(args: {
return buildFallbackManualOrderUpdates(args.orderedIds, args.now)
}

// Why: any non-moved row without a persisted manualOrder would otherwise keep
// falling back to the mutable sortOrder in the comparator and jump on later
// activity, so backfill the whole visible group instead of sparse-ranking only
// the moved rows.
const ranks = args.rankByWorktreeId
if (
ranks !== undefined &&
args.orderedIds.some((id) => !movedSet.has(id) && getManualOrderRank(ranks, id) === null)
) {
return buildFallbackManualOrderUpdates(args.orderedIds, args.now)
}

const firstMovedIndex = args.orderedIds.findIndex((id) => movedSet.has(id))
const lastMovedIndex = args.orderedIds.findLastIndex((id) => movedSet.has(id))
const beforeId = args.orderedIds.slice(0, firstMovedIndex).findLast((id) => !movedSet.has(id))
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/src/components/sidebar/worktree-manual-order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,27 @@ describe('buildManualOrderUpdatesForVisibleGroups', () => {
expect(Array.from(result.updates)).toEqual([['b', { manualOrder: 0 }]])
})

it('backfills manualOrder for every visible row when an unmoved row lacks one', () => {
// Why: an unmoved row without a persisted manualOrder would otherwise keep
// falling back to the mutable sortOrder in the comparator and jump on later
// activity, so a reorder must stamp every visible row — not just the moved one.
const result = buildManualOrderUpdatesForVisibleGroups({
groups: [{ key: 'repo:one', worktreeIds: ['a', 'b', 'c', 'd'] }],
sourceGroupKey: 'repo:one',
draggedIds: ['b'],
dropIndex: 4,
now: 10_000,
rankByWorktreeId: new Map([
['a', 4000],
['b', 3000],
['d', 1000]
])
})

expect(result.orderedIds).toEqual(['a', 'c', 'd', 'b'])
expect(Array.from(result.updates.keys()).sort()).toEqual(['a', 'b', 'c', 'd'])
})

it('moves an expanded lineage cluster as one ranked unit', () => {
const result = buildManualOrderUpdatesForVisibleGroups({
groups: [{ key: 'all', worktreeIds: ['parent', 'child', 'other'] }],
Expand Down