preserve prompt draft when browsing history
This commit is contained in:
@@ -23,6 +23,7 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
const [prompt, setPromptInternal] = createSignal("")
|
const [prompt, setPromptInternal] = createSignal("")
|
||||||
const [history, setHistory] = createSignal<string[]>([])
|
const [history, setHistory] = createSignal<string[]>([])
|
||||||
const [historyIndex, setHistoryIndex] = createSignal(-1)
|
const [historyIndex, setHistoryIndex] = createSignal(-1)
|
||||||
|
const [historyDraft, setHistoryDraft] = createSignal<string | null>(null)
|
||||||
const [isFocused, setIsFocused] = createSignal(false)
|
const [isFocused, setIsFocused] = createSignal(false)
|
||||||
const [showPicker, setShowPicker] = createSignal(false)
|
const [showPicker, setShowPicker] = createSignal(false)
|
||||||
const [searchQuery, setSearchQuery] = createSignal("")
|
const [searchQuery, setSearchQuery] = createSignal("")
|
||||||
@@ -48,6 +49,7 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
const clearPrompt = () => {
|
const clearPrompt = () => {
|
||||||
clearSessionDraftPrompt(props.instanceId, props.sessionId)
|
clearSessionDraftPrompt(props.instanceId, props.sessionId)
|
||||||
setPromptInternal("")
|
setPromptInternal("")
|
||||||
|
setHistoryDraft(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncAttachmentCounters(currentPrompt: string, sessionAttachments: Attachment[]) {
|
function syncAttachmentCounters(currentPrompt: string, sessionAttachments: Attachment[]) {
|
||||||
@@ -110,6 +112,7 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
setPromptInternal(storedPrompt)
|
setPromptInternal(storedPrompt)
|
||||||
setSessionDraftPrompt(instanceId, sessionId, storedPrompt)
|
setSessionDraftPrompt(instanceId, sessionId, storedPrompt)
|
||||||
setHistoryIndex(-1)
|
setHistoryIndex(-1)
|
||||||
|
setHistoryDraft(null)
|
||||||
setIgnoredAtPositions(new Set<number>())
|
setIgnoredAtPositions(new Set<number>())
|
||||||
setShowPicker(false)
|
setShowPicker(false)
|
||||||
setAtPosition(null)
|
setAtPosition(null)
|
||||||
@@ -433,6 +436,9 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
|
|
||||||
if (e.key === "ArrowUp" && !showPicker() && atStart && currentHistory.length > 0) {
|
if (e.key === "ArrowUp" && !showPicker() && atStart && currentHistory.length > 0) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
if (historyIndex() === -1) {
|
||||||
|
setHistoryDraft(prompt())
|
||||||
|
}
|
||||||
const newIndex = historyIndex() === -1 ? 0 : Math.min(historyIndex() + 1, currentHistory.length - 1)
|
const newIndex = historyIndex() === -1 ? 0 : Math.min(historyIndex() + 1, currentHistory.length - 1)
|
||||||
setHistoryIndex(newIndex)
|
setHistoryIndex(newIndex)
|
||||||
setPrompt(currentHistory[newIndex])
|
setPrompt(currentHistory[newIndex])
|
||||||
@@ -447,7 +453,9 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
setPrompt(currentHistory[newIndex])
|
setPrompt(currentHistory[newIndex])
|
||||||
} else {
|
} else {
|
||||||
setHistoryIndex(-1)
|
setHistoryIndex(-1)
|
||||||
setPrompt("")
|
const draft = historyDraft()
|
||||||
|
setPrompt(draft ?? "")
|
||||||
|
setHistoryDraft(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,6 +470,7 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
setIgnoredAtPositions(new Set<number>())
|
setIgnoredAtPositions(new Set<number>())
|
||||||
setPasteCount(0)
|
setPasteCount(0)
|
||||||
setImageCount(0)
|
setImageCount(0)
|
||||||
|
setHistoryDraft(null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await addToHistory(props.instanceFolder, text)
|
await addToHistory(props.instanceFolder, text)
|
||||||
@@ -482,6 +491,7 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
const value = target.value
|
const value = target.value
|
||||||
setPrompt(value)
|
setPrompt(value)
|
||||||
setHistoryIndex(-1)
|
setHistoryIndex(-1)
|
||||||
|
setHistoryDraft(null)
|
||||||
|
|
||||||
const cursorPos = target.selectionStart
|
const cursorPos = target.selectionStart
|
||||||
const textBeforeCursor = value.substring(0, cursorPos)
|
const textBeforeCursor = value.substring(0, cursorPos)
|
||||||
|
|||||||
Reference in New Issue
Block a user