Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions webview-ui/src/components/chat/ChatTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface ChatTextAreaProps {
selectedImages: string[]
setSelectedImages: React.Dispatch<React.SetStateAction<string[]>>
onSend: () => void
onAccept?: () => void // Called when Enter should trigger approval (when action buttons are visible)
onSelectImages: () => void
shouldDisableImages: boolean
onHeightChange?: (height: number) => void
Expand All @@ -66,6 +67,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
selectedImages,
setSelectedImages,
onSend,
onAccept,
onSelectImages,
shouldDisableImages,
onHeightChange,
Expand Down Expand Up @@ -486,20 +488,23 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(

// Handle Enter key based on enterBehavior setting
if (event.key === "Enter" && !isComposing) {
// Determine the action handler: use onAccept if provided (for approval behavior), otherwise onSend
const actionHandler = onAccept ?? onSend

if (enterBehavior === "newline") {
// New behavior: Enter = newline, Shift+Enter or Ctrl+Enter = send
// New behavior: Enter = newline, Shift+Enter or Ctrl+Enter = send/accept
if (event.shiftKey || event.ctrlKey || event.metaKey) {
event.preventDefault()
resetHistoryNavigation()
onSend()
actionHandler()
}
// Otherwise, let Enter create newline (don't preventDefault)
} else {
// Default behavior: Enter = send, Shift+Enter = newline
// Default behavior: Enter = send/accept, Shift+Enter = newline
if (!event.shiftKey) {
event.preventDefault()
resetHistoryNavigation()
onSend()
actionHandler()
}
}
}
Expand Down Expand Up @@ -550,6 +555,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
},
[
onSend,
onAccept,
showContextMenu,
searchQuery,
selectedMenuIndex,
Expand Down
6 changes: 6 additions & 0 deletions webview-ui/src/components/chat/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,12 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
selectedImages={selectedImages}
setSelectedImages={setSelectedImages}
onSend={() => handleSendMessage(inputValue, selectedImages)}
onAccept={
// When action buttons are visible, Enter should trigger approval (primary button click)
enableButtons && primaryButtonText
? () => handlePrimaryButtonClick(inputValue, selectedImages)
: undefined
}
onSelectImages={selectImages}
shouldDisableImages={shouldDisableImages}
onHeightChange={() => {
Expand Down
Loading