Send the text when the buttons are clicked

This commit is contained in:
Nathan Apter
2025-01-29 15:17:30 -05:00
parent 3aa5b3f9be
commit fe82500e94

View File

@@ -337,7 +337,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
/* /*
This logic depends on the useEffect[messages] above to set clineAsk, after which buttons are shown and we then send an askResponse to the extension. This logic depends on the useEffect[messages] above to set clineAsk, after which buttons are shown and we then send an askResponse to the extension.
*/ */
const handlePrimaryButtonClick = useCallback(() => { const handlePrimaryButtonClick = useCallback(
(text?: string, images?: string[]) => {
const trimmedInput = text?.trim()
switch (clineAsk) { switch (clineAsk) {
case "api_req_failed": case "api_req_failed":
case "command": case "command":
@@ -347,7 +349,23 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
case "use_mcp_server": case "use_mcp_server":
case "resume_task": case "resume_task":
case "mistake_limit_reached": case "mistake_limit_reached":
vscode.postMessage({ type: "askResponse", askResponse: "yesButtonClicked" }) // Only send text/images if they exist
if (trimmedInput || (images && images.length > 0)) {
vscode.postMessage({
type: "askResponse",
askResponse: "yesButtonClicked",
text: trimmedInput,
images: images,
})
} else {
vscode.postMessage({
type: "askResponse",
askResponse: "yesButtonClicked",
})
}
// Clear input state after sending
setInputValue("")
setSelectedImages([])
break break
case "completion_result": case "completion_result":
case "resume_completed_task": case "resume_completed_task":
@@ -359,9 +377,13 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
setClineAsk(undefined) setClineAsk(undefined)
setEnableButtons(false) setEnableButtons(false)
disableAutoScrollRef.current = false disableAutoScrollRef.current = false
}, [clineAsk, startNewTask]) },
[clineAsk, startNewTask],
)
const handleSecondaryButtonClick = useCallback(() => { const handleSecondaryButtonClick = useCallback(
(text?: string, images?: string[]) => {
const trimmedInput = text?.trim()
if (isStreaming) { if (isStreaming) {
vscode.postMessage({ type: "cancelTask" }) vscode.postMessage({ type: "cancelTask" })
setDidClickCancel(true) setDidClickCancel(true)
@@ -378,15 +400,33 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
case "tool": case "tool":
case "browser_action_launch": case "browser_action_launch":
case "use_mcp_server": case "use_mcp_server":
// Only send text/images if they exist
if (trimmedInput || (images && images.length > 0)) {
vscode.postMessage({
type: "askResponse",
askResponse: "noButtonClicked",
text: trimmedInput,
images: images,
})
} else {
// responds to the API with a "This operation failed" and lets it try again // responds to the API with a "This operation failed" and lets it try again
vscode.postMessage({ type: "askResponse", askResponse: "noButtonClicked" }) vscode.postMessage({
type: "askResponse",
askResponse: "noButtonClicked",
})
}
// Clear input state after sending
setInputValue("")
setSelectedImages([])
break break
} }
setTextAreaDisabled(true) setTextAreaDisabled(true)
setClineAsk(undefined) setClineAsk(undefined)
setEnableButtons(false) setEnableButtons(false)
disableAutoScrollRef.current = false disableAutoScrollRef.current = false
}, [clineAsk, startNewTask, isStreaming]) },
[clineAsk, startNewTask, isStreaming],
)
const handleTaskCloseButtonClick = useCallback(() => { const handleTaskCloseButtonClick = useCallback(() => {
startNewTask() startNewTask()
@@ -430,10 +470,10 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
handleSendMessage(message.text ?? "", message.images ?? []) handleSendMessage(message.text ?? "", message.images ?? [])
break break
case "primaryButtonClick": case "primaryButtonClick":
handlePrimaryButtonClick() handlePrimaryButtonClick(message.text ?? "", message.images ?? [])
break break
case "secondaryButtonClick": case "secondaryButtonClick":
handleSecondaryButtonClick() handleSecondaryButtonClick(message.text ?? "", message.images ?? [])
break break
} }
} }
@@ -1038,7 +1078,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
flex: secondaryButtonText ? 1 : 2, flex: secondaryButtonText ? 1 : 2,
marginRight: secondaryButtonText ? "6px" : "0", marginRight: secondaryButtonText ? "6px" : "0",
}} }}
onClick={handlePrimaryButtonClick}> onClick={(e) => handlePrimaryButtonClick(inputValue, selectedImages)}>
{primaryButtonText} {primaryButtonText}
</VSCodeButton> </VSCodeButton>
)} )}
@@ -1050,7 +1090,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
flex: isStreaming ? 2 : 1, flex: isStreaming ? 2 : 1,
marginLeft: isStreaming ? 0 : "6px", marginLeft: isStreaming ? 0 : "6px",
}} }}
onClick={handleSecondaryButtonClick}> onClick={(e) => handleSecondaryButtonClick(inputValue, selectedImages)}>
{isStreaming ? "Cancel" : secondaryButtonText} {isStreaming ? "Cancel" : secondaryButtonText}
</VSCodeButton> </VSCodeButton>
)} )}