1- import { memo } from "react" ;
1+ import { memo , type PointerEventHandler } from "react" ;
22import { ChevronDownIcon , ChevronLeftIcon } from "lucide-react" ;
33import { cn } from "~/lib/utils" ;
44import { Button } from "../ui/button" ;
@@ -22,6 +22,7 @@ interface ComposerPrimaryActionsProps {
2222 isConnecting : boolean ;
2323 isPreparingWorktree : boolean ;
2424 hasSendableContent : boolean ;
25+ preserveComposerFocusOnPointerDown ?: boolean ;
2526 onPreviousPendingQuestion : ( ) => void ;
2627 onInterrupt : ( ) => void ;
2728 onImplementPlanInNewThread : ( ) => void ;
@@ -45,6 +46,10 @@ export const formatPendingPrimaryActionLabel = (input: {
4546 return input . questionIndex > 0 ? "Submit answers" : "Submit answer" ;
4647} ;
4748
49+ const preventPointerFocus : PointerEventHandler < HTMLElement > = ( event ) => {
50+ event . preventDefault ( ) ;
51+ } ;
52+
4853export const ComposerPrimaryActions = memo ( function ComposerPrimaryActions ( {
4954 compact,
5055 pendingAction,
@@ -55,10 +60,15 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
5560 isConnecting,
5661 isPreparingWorktree,
5762 hasSendableContent,
63+ preserveComposerFocusOnPointerDown = false ,
5864 onPreviousPendingQuestion,
5965 onInterrupt,
6066 onImplementPlanInNewThread,
6167} : ComposerPrimaryActionsProps ) {
68+ const pointerFocusProps = preserveComposerFocusOnPointerDown
69+ ? { onPointerDown : preventPointerFocus }
70+ : undefined ;
71+
6272 if ( pendingAction ) {
6373 return (
6474 < div className = { cn ( "flex items-center justify-end" , compact ? "gap-1.5" : "gap-2" ) } >
@@ -68,7 +78,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
6878 size = "icon-sm"
6979 variant = "outline"
7080 className = "rounded-full"
71- onPointerDown = { ( event ) => event . preventDefault ( ) }
81+ { ... pointerFocusProps }
7282 onClick = { onPreviousPendingQuestion }
7383 disabled = { pendingAction . isResponding }
7484 aria-label = "Previous question"
@@ -80,7 +90,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
8090 size = "sm"
8191 variant = "outline"
8292 className = "rounded-full"
83- onPointerDown = { ( event ) => event . preventDefault ( ) }
93+ { ... pointerFocusProps }
8494 onClick = { onPreviousPendingQuestion }
8595 disabled = { pendingAction . isResponding }
8696 >
@@ -92,7 +102,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
92102 type = "submit"
93103 size = "sm"
94104 className = { cn ( "rounded-full" , compact ? "px-3" : "px-4" ) }
95- onPointerDown = { ( event ) => event . preventDefault ( ) }
105+ { ... pointerFocusProps }
96106 disabled = {
97107 pendingAction . isResponding ||
98108 ( pendingAction . isLastQuestion ? ! pendingAction . isComplete : ! pendingAction . canAdvance )
@@ -114,7 +124,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
114124 < button
115125 type = "button"
116126 className = "flex size-8 cursor-pointer items-center justify-center rounded-full bg-rose-500/90 text-white transition-all duration-150 hover:bg-rose-500 hover:scale-105 sm:h-8 sm:w-8"
117- onPointerDown = { ( event ) => event . preventDefault ( ) }
127+ { ... pointerFocusProps }
118128 onClick = { onInterrupt }
119129 aria-label = "Stop generation"
120130 >
@@ -132,7 +142,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
132142 type = "submit"
133143 size = "sm"
134144 className = { cn ( "rounded-full" , compact ? "h-9 px-3 sm:h-8" : "h-9 px-4 sm:h-8" ) }
135- onPointerDown = { ( event ) => event . preventDefault ( ) }
145+ { ... pointerFocusProps }
136146 disabled = { isSendBusy || isConnecting }
137147 >
138148 { isConnecting || isSendBusy ? "Sending..." : "Refine" }
@@ -146,7 +156,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
146156 type = "submit"
147157 size = "sm"
148158 className = "h-9 rounded-l-full rounded-r-none px-4 sm:h-8"
149- onPointerDown = { ( event ) => event . preventDefault ( ) }
159+ { ... pointerFocusProps }
150160 disabled = { isSendBusy || isConnecting }
151161 >
152162 { isConnecting || isSendBusy ? "Sending..." : "Implement" }
@@ -159,7 +169,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
159169 variant = "default"
160170 className = "h-9 rounded-l-none rounded-r-full border-l-white/12 px-2 sm:h-8"
161171 aria-label = "Implementation actions"
162- onPointerDown = { ( event ) => event . preventDefault ( ) }
172+ { ... pointerFocusProps }
163173 disabled = { isSendBusy || isConnecting }
164174 />
165175 }
@@ -183,7 +193,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
183193 < button
184194 type = "submit"
185195 className = "flex h-9 w-9 enabled:cursor-pointer items-center justify-center rounded-full bg-primary/90 text-primary-foreground transition-all duration-150 hover:bg-primary hover:scale-105 disabled:pointer-events-none disabled:opacity-30 disabled:hover:scale-100 sm:h-8 sm:w-8"
186- onPointerDown = { ( event ) => event . preventDefault ( ) }
196+ { ... pointerFocusProps }
187197 disabled = { isSendBusy || isConnecting || ! hasSendableContent }
188198 aria-label = {
189199 isConnecting
0 commit comments