Skip to content

Commit 36dfe16

Browse files
authored
fix(app): only navigate prompt history when input is empty (#18775)
1 parent 6926dc2 commit 36dfe16

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

packages/app/e2e/prompt/prompt-history.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ test("prompt history restores unsent draft with arrow navigation", async ({ page
108108
await page.keyboard.type(draft)
109109
await wait(page, draft)
110110

111-
await edge(page, "start")
111+
// Clear the draft before navigating history (ArrowUp only works when prompt is empty)
112+
await prompt.fill("")
113+
await wait(page, "")
114+
112115
await page.keyboard.press("ArrowUp")
113116
await wait(page, second)
114117

@@ -119,7 +122,7 @@ test("prompt history restores unsent draft with arrow navigation", async ({ page
119122
await wait(page, second)
120123

121124
await page.keyboard.press("ArrowDown")
122-
await wait(page, draft)
125+
await wait(page, "")
123126
})
124127
})
125128

packages/app/src/components/prompt-input/history.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe("prompt-input history", () => {
126126
test("canNavigateHistoryAtCursor only allows prompt boundaries", () => {
127127
const value = "a\nb\nc"
128128

129-
expect(canNavigateHistoryAtCursor("up", value, 0)).toBe(true)
129+
expect(canNavigateHistoryAtCursor("up", value, 0)).toBe(false)
130130
expect(canNavigateHistoryAtCursor("down", value, 0)).toBe(false)
131131

132132
expect(canNavigateHistoryAtCursor("up", value, 2)).toBe(false)
@@ -135,11 +135,14 @@ describe("prompt-input history", () => {
135135
expect(canNavigateHistoryAtCursor("up", value, 5)).toBe(false)
136136
expect(canNavigateHistoryAtCursor("down", value, 5)).toBe(true)
137137

138-
expect(canNavigateHistoryAtCursor("up", "abc", 0)).toBe(true)
138+
expect(canNavigateHistoryAtCursor("up", "abc", 0)).toBe(false)
139139
expect(canNavigateHistoryAtCursor("down", "abc", 3)).toBe(true)
140140
expect(canNavigateHistoryAtCursor("up", "abc", 1)).toBe(false)
141141
expect(canNavigateHistoryAtCursor("down", "abc", 1)).toBe(false)
142142

143+
expect(canNavigateHistoryAtCursor("up", "", 0)).toBe(true)
144+
expect(canNavigateHistoryAtCursor("down", "", 0)).toBe(true)
145+
143146
expect(canNavigateHistoryAtCursor("up", "abc", 0, true)).toBe(true)
144147
expect(canNavigateHistoryAtCursor("up", "abc", 3, true)).toBe(true)
145148
expect(canNavigateHistoryAtCursor("down", "abc", 0, true)).toBe(true)

packages/app/src/components/prompt-input/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function canNavigateHistoryAtCursor(direction: "up" | "down", text: strin
2727
const atStart = position === 0
2828
const atEnd = position === text.length
2929
if (inHistory) return atStart || atEnd
30-
if (direction === "up") return position === 0
30+
if (direction === "up") return position === 0 && text.length === 0
3131
return position === text.length
3232
}
3333

0 commit comments

Comments
 (0)