diff options
| author | Adam <[email protected]> | 2025-12-16 15:42:31 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-12-16 15:42:35 -0600 |
| commit | f07d4b933c015310bbb7703c02b2672595a2aef6 (patch) | |
| tree | 2e38d5aedf2d24ab4cd54f74abf7438e83ba5e78 | |
| parent | 5f57cee8e46abc6b1368c10991a22b2d676cf2a4 (diff) | |
| download | opencode-f07d4b933c015310bbb7703c02b2672595a2aef6.tar.gz opencode-f07d4b933c015310bbb7703c02b2672595a2aef6.zip | |
fix(desktop): prompt history nav
| -rw-r--r-- | packages/desktop/src/components/prompt-input.tsx | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/packages/desktop/src/components/prompt-input.tsx b/packages/desktop/src/components/prompt-input.tsx index b152ff0f5..aea9f4e23 100644 --- a/packages/desktop/src/components/prompt-input.tsx +++ b/packages/desktop/src/components/prompt-input.tsx @@ -598,19 +598,24 @@ export const PromptInput: Component<PromptInputProps> = (props) => { const cursorPosition = getCursorPosition(editorRef) const textLength = promptLength(prompt.current()) + const textContent = editorRef.textContent ?? "" + const isEmpty = textContent.trim() === "" || textLength <= 1 + const hasNewlines = textContent.includes("\n") const inHistory = store.historyIndex >= 0 - const atStart = cursorPosition <= 0 - const atEnd = cursorPosition >= textLength + const atStart = cursorPosition <= (isEmpty ? 1 : 0) + const atEnd = cursorPosition >= (isEmpty ? textLength - 1 : textLength) + const allowUp = isEmpty || atStart || (!hasNewlines && !inHistory) || (inHistory && atEnd) + const allowDown = isEmpty || atEnd || (!hasNewlines && !inHistory) || (inHistory && atStart) if (event.key === "ArrowUp") { - if (!atStart && !(inHistory && atEnd)) return + if (!allowUp) return if (navigateHistory("up")) { event.preventDefault() } return } - if (!atEnd && !(inHistory && atStart)) return + if (!allowDown) return if (navigateHistory("down")) { event.preventDefault() } |
