diff --git a/packages/app/src/workspaces/selection/domain.test.ts b/packages/app/src/workspaces/selection/domain.test.ts index 7f9579a8aa6..27712c2c5ce 100644 --- a/packages/app/src/workspaces/selection/domain.test.ts +++ b/packages/app/src/workspaces/selection/domain.test.ts @@ -561,6 +561,7 @@ test("listing a folder passes the abort signal to the request", async () => { test("wraps autocomplete keyboard navigation", () => { expect(nextSuggestionIndex(-1, 1, 4)).toBe(0) + expect(nextSuggestionIndex(-1, -1, 4)).toBe(3) expect(nextSuggestionIndex(3, 1, 4)).toBe(0) expect(nextSuggestionIndex(0, -1, 4)).toBe(3) expect(nextSuggestionIndex(0, 1, 0)).toBe(-1) diff --git a/packages/app/src/workspaces/selection/domain.ts b/packages/app/src/workspaces/selection/domain.ts index 8899d64f379..f87570cba72 100644 --- a/packages/app/src/workspaces/selection/domain.ts +++ b/packages/app/src/workspaces/selection/domain.ts @@ -215,6 +215,7 @@ export function createPriorityTaskQueue(concurrency: number) { export function nextSuggestionIndex(current: number, delta: -1 | 1, count: number) { if (count === 0) return -1 + if (current < 0) return delta > 0 ? 0 : count - 1 return (current + delta + count) % count }