|
1 | 1 | import { ClineMessage, HistoryItem } from "@roo-code/types" |
2 | | -import { useCallback, useEffect, useMemo, useState } from "react" |
| 2 | +import { useCallback, useEffect, useMemo, useRef, useState } from "react" |
3 | 3 |
|
4 | 4 | interface UsePromptHistoryProps { |
5 | 5 | clineMessages: ClineMessage[] | undefined |
@@ -38,6 +38,8 @@ export const usePromptHistory = ({ |
38 | 38 | const [historyIndex, setHistoryIndex] = useState(-1) |
39 | 39 | const [tempInput, setTempInput] = useState("") |
40 | 40 | const [promptHistory, setPromptHistory] = useState<string[]>([]) |
| 41 | + const historySource = clineMessages?.length ? "conversation" : "task" |
| 42 | + const previousHistorySource = useRef(historySource) |
41 | 43 |
|
42 | 44 | // Initialize prompt history with hybrid approach: conversation messages if in task, otherwise task history |
43 | 45 | const filteredPromptHistory = useMemo(() => { |
@@ -74,14 +76,18 @@ export const usePromptHistory = ({ |
74 | 76 | const historyChanged = |
75 | 77 | promptHistory.length !== filteredPromptHistory.length || |
76 | 78 | promptHistory.some((prompt, index) => prompt !== filteredPromptHistory[index]) |
| 79 | + const historySourceChanged = previousHistorySource.current !== historySource |
| 80 | + previousHistorySource.current = historySource |
77 | 81 |
|
78 | | - if (!historyChanged) return |
| 82 | + if (!historyChanged && !historySourceChanged) return |
79 | 83 |
|
80 | | - setPromptHistory(filteredPromptHistory) |
| 84 | + if (historyChanged) { |
| 85 | + setPromptHistory(filteredPromptHistory) |
| 86 | + } |
81 | 87 | // Reset navigation state when switching between history sources |
82 | 88 | setHistoryIndex(-1) |
83 | 89 | setTempInput("") |
84 | | - }, [filteredPromptHistory, promptHistory]) |
| 90 | + }, [filteredPromptHistory, historySource, promptHistory]) |
85 | 91 |
|
86 | 92 | // Reset history navigation when user types (but not when we're setting it programmatically) |
87 | 93 | const resetOnInputChange = useCallback(() => { |
|
0 commit comments