summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/components/prompt-input
diff options
context:
space:
mode:
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 {