Skip to content

Commit d1f15ba

Browse files
committed
fix: correct prompt history order and add workspace filtering (#4139)
- Remove reverse() to maintain chronological order in history array - Add workspace filtering to only show prompts from current workspace - Ensure arrow up navigates to older prompts (as expected) - Filter history items by workspace field matching current cwd
1 parent 4000aef commit d1f15ba

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,21 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
161161

162162
// Initialize prompt history from task history
163163
useEffect(() => {
164-
if (taskHistory && taskHistory.length > 0) {
165-
// Extract user prompts from task history
164+
if (taskHistory && taskHistory.length > 0 && cwd) {
165+
// Extract user prompts from task history for the current workspace only
166166
const prompts = taskHistory
167-
.filter((item) => item.task && item.task.trim() !== "")
167+
.filter((item) => {
168+
// Filter by workspace and ensure task is not empty
169+
return item.task && item.task.trim() !== "" && (!item.workspace || item.workspace === cwd)
170+
})
168171
.map((item) => item.task)
169-
.reverse() // Most recent first
172+
// taskHistory is already in chronological order (oldest first)
173+
// We keep it as-is so that navigation works correctly:
174+
// - Arrow up increases index to go back in history (older prompts)
175+
// - Arrow down decreases index to go forward (newer prompts)
170176
setPromptHistory(prompts)
171177
}
172-
}, [taskHistory])
178+
}, [taskHistory, cwd])
173179

174180
// Fetch git commits when Git is selected or when typing a hash.
175181
useEffect(() => {

0 commit comments

Comments
 (0)