summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/components/prompt-input
diff options
context:
space:
mode:
authorShoubhit Dash <[email protected]>2026-02-15 19:17:19 +0530
committerGitHub <[email protected]>2026-02-15 07:47:19 -0600
commit3c85cf4fac596928713685068c6c92f356b848f3 (patch)
tree2f6a2b003b09b8e99ba6a1f4f46c6c4ac4dbde21 /packages/app/src/components/prompt-input
parent878ddc6a0a9eff4fe990dfc241a8eb1c72f0659d (diff)
downloadopencode-3c85cf4fac596928713685068c6c92f356b848f3.tar.gz
opencode-3c85cf4fac596928713685068c6c92f356b848f3.zip
fix(app): only navigate prompt history at input boundaries (#13690)
Diffstat (limited to 'packages/app/src/components/prompt-input')
-rw-r--r--packages/app/src/components/prompt-input/history.test.ts15
-rw-r--r--packages/app/src/components/prompt-input/history.ts10
2 files changed, 18 insertions, 7 deletions
diff --git a/packages/app/src/components/prompt-input/history.test.ts b/packages/app/src/components/prompt-input/history.test.ts
index a37fdad67..b7a4f896b 100644
--- a/packages/app/src/components/prompt-input/history.test.ts
+++ b/packages/app/src/components/prompt-input/history.test.ts
@@ -73,7 +73,7 @@ describe("prompt-input history", () => {
expect(original[1].selection?.startLine).toBe(1)
})
- test("canNavigateHistoryAtCursor only allows multiline boundaries", () => {
+ test("canNavigateHistoryAtCursor only allows prompt boundaries", () => {
const value = "a\nb\nc"
expect(canNavigateHistoryAtCursor("up", value, 0)).toBe(true)
@@ -85,7 +85,16 @@ describe("prompt-input history", () => {
expect(canNavigateHistoryAtCursor("up", value, 5)).toBe(false)
expect(canNavigateHistoryAtCursor("down", value, 5)).toBe(true)
- expect(canNavigateHistoryAtCursor("up", "abc", 1)).toBe(true)
- expect(canNavigateHistoryAtCursor("down", "abc", 1)).toBe(true)
+ expect(canNavigateHistoryAtCursor("up", "abc", 0)).toBe(true)
+ expect(canNavigateHistoryAtCursor("down", "abc", 3)).toBe(true)
+ expect(canNavigateHistoryAtCursor("up", "abc", 1)).toBe(false)
+ expect(canNavigateHistoryAtCursor("down", "abc", 1)).toBe(false)
+
+ expect(canNavigateHistoryAtCursor("up", "abc", 0, true)).toBe(true)
+ expect(canNavigateHistoryAtCursor("up", "abc", 3, true)).toBe(true)
+ expect(canNavigateHistoryAtCursor("down", "abc", 0, true)).toBe(true)
+ expect(canNavigateHistoryAtCursor("down", "abc", 3, true)).toBe(true)
+ expect(canNavigateHistoryAtCursor("up", "abc", 1, true)).toBe(false)
+ expect(canNavigateHistoryAtCursor("down", "abc", 1, true)).toBe(false)
})
})
diff --git a/packages/app/src/components/prompt-input/history.ts b/packages/app/src/components/prompt-input/history.ts
index f26f80848..c279a3ed5 100644
--- a/packages/app/src/components/prompt-input/history.ts
+++ b/packages/app/src/components/prompt-input/history.ts
@@ -4,11 +4,13 @@ const DEFAULT_PROMPT: Prompt = [{ type: "text", content: "", start: 0, end: 0 }]
export const MAX_HISTORY = 100
-export function canNavigateHistoryAtCursor(direction: "up" | "down", text: string, cursor: number) {
- if (!text.includes("\n")) return true
+export function canNavigateHistoryAtCursor(direction: "up" | "down", text: string, cursor: number, inHistory = false) {
const position = Math.max(0, Math.min(cursor, text.length))
- if (direction === "up") return !text.slice(0, position).includes("\n")
- return !text.slice(position).includes("\n")
+ const atStart = position === 0
+ const atEnd = position === text.length
+ if (inHistory) return atStart || atEnd
+ if (direction === "up") return position === 0
+ return position === text.length
}
export function clonePromptParts(prompt: Prompt): Prompt {