GeezerVison is showing github.com — fix(app): only navigate prompt history at input boundaries (#13690) · motionharvest/opencode@3c85cf4
File treeExpand file treeCollapse file tree Open diff view settings packages/app/src/components
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/prompt-input.tsx +2-20Lines changed: 2 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -911,31 +911,13 @@ export const PromptInput: Component<PromptInputProps> = (props) => { | 911 | 911 | if (!collapsed) return | 912 | 912 |
| 913 | 913 | const cursorPosition = getCursorPosition(editorRef) | 914 | | - const textLength = promptLength(prompt.current()) | 915 | 914 | const textContent = prompt | 916 | 915 | .current() | 917 | 916 | .map((part) => ("content" in part ? part.content : "")) | 918 | 917 | .join("") | 919 | 918 | const direction = event.key === "ArrowUp" ? "up" : "down" | 920 | | - if (!canNavigateHistoryAtCursor(direction, textContent, cursorPosition)) return | 921 | | - const isEmpty = textContent.trim() === "" || textLength <= 1 | 922 | | - const hasNewlines = textContent.includes("\n") | 923 | | - const inHistory = store.historyIndex >= 0 | 924 | | - const atStart = cursorPosition <= (isEmpty ? 1 : 0) | 925 | | - const atEnd = cursorPosition >= (isEmpty ? textLength - 1 : textLength) | 926 | | - const allowUp = isEmpty || atStart || (!hasNewlines && !inHistory) || (inHistory && atEnd) | 927 | | - const allowDown = isEmpty || atEnd || (!hasNewlines && !inHistory) || (inHistory && atStart) | 928 | | - | 929 | | - if (direction === "up") { | 930 | | - if (!allowUp) return | 931 | | - if (navigateHistory("up")) { | 932 | | - event.preventDefault() | 933 | | - } | 934 | | - return | 935 | | - } | 936 | | - | 937 | | - if (!allowDown) return | 938 | | - if (navigateHistory("down")) { | | 919 | + if (!canNavigateHistoryAtCursor(direction, textContent, cursorPosition, store.historyIndex >= 0)) return | | 920 | + if (navigateHistory(direction)) { | 939 | 921 | event.preventDefault() | 940 | 922 | } | 941 | 923 | return | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/prompt-input/history.test.ts +12-3Lines changed: 12 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -73,7 +73,7 @@ describe("prompt-input history", () => { | 73 | 73 | expect(original[1].selection?.startLine).toBe(1) | 74 | 74 | }) | 75 | 75 |
| 76 | | - test("canNavigateHistoryAtCursor only allows multiline boundaries", () => { | | 76 | + test("canNavigateHistoryAtCursor only allows prompt boundaries", () => { | 77 | 77 | const value = "a\nb\nc" | 78 | 78 |
| 79 | 79 | expect(canNavigateHistoryAtCursor("up", value, 0)).toBe(true) | @@ -85,7 +85,16 @@ describe("prompt-input history", () => { | 85 | 85 | expect(canNavigateHistoryAtCursor("up", value, 5)).toBe(false) | 86 | 86 | expect(canNavigateHistoryAtCursor("down", value, 5)).toBe(true) | 87 | 87 |
| 88 | | - expect(canNavigateHistoryAtCursor("up", "abc", 1)).toBe(true) | 89 | | - expect(canNavigateHistoryAtCursor("down", "abc", 1)).toBe(true) | | 88 | + expect(canNavigateHistoryAtCursor("up", "abc", 0)).toBe(true) | | 89 | + expect(canNavigateHistoryAtCursor("down", "abc", 3)).toBe(true) | | 90 | + expect(canNavigateHistoryAtCursor("up", "abc", 1)).toBe(false) | | 91 | + expect(canNavigateHistoryAtCursor("down", "abc", 1)).toBe(false) | | 92 | + | | 93 | + expect(canNavigateHistoryAtCursor("up", "abc", 0, true)).toBe(true) | | 94 | + expect(canNavigateHistoryAtCursor("up", "abc", 3, true)).toBe(true) | | 95 | + expect(canNavigateHistoryAtCursor("down", "abc", 0, true)).toBe(true) | | 96 | + expect(canNavigateHistoryAtCursor("down", "abc", 3, true)).toBe(true) | | 97 | + expect(canNavigateHistoryAtCursor("up", "abc", 1, true)).toBe(false) | | 98 | + expect(canNavigateHistoryAtCursor("down", "abc", 1, true)).toBe(false) | 90 | 99 | }) | 91 | 100 | }) |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/prompt-input/history.ts +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,11 +4,13 @@ const DEFAULT_PROMPT: Prompt = [{ type: "text", content: "", start: 0, end: 0 }] | 4 | 4 |
| 5 | 5 | export const MAX_HISTORY = 100 | 6 | 6 |
| 7 | | -export function canNavigateHistoryAtCursor(direction: "up" | "down", text: string, cursor: number) { | 8 | | - if (!text.includes("\n")) return true | | 7 | +export function canNavigateHistoryAtCursor(direction: "up" | "down", text: string, cursor: number, inHistory = false) { | 9 | 8 | const position = Math.max(0, Math.min(cursor, text.length)) | 10 | | - if (direction === "up") return !text.slice(0, position).includes("\n") | 11 | | - return !text.slice(position).includes("\n") | | 9 | + const atStart = position === 0 | | 10 | + const atEnd = position === text.length | | 11 | + if (inHistory) return atStart || atEnd | | 12 | + if (direction === "up") return position === 0 | | 13 | + return position === text.length | 12 | 14 | } | 13 | 15 |
| 14 | 16 | export function clonePromptParts(prompt: Prompt): Prompt { | |
|