@@ -77,6 +77,7 @@ import {
7777 collapseExpandedComposerCursor ,
7878 composerSubmissionIntentForKey ,
7979 composerStateAtPromptEnd ,
80+ composerStateForReturningDraft ,
8081 detectComposerTrigger ,
8182 expandCollapsedComposerCursor ,
8283 formatAssistantCitationForComposer ,
@@ -1546,6 +1547,7 @@ export interface ChatComposerProps {
15461547 activePendingApproval : PendingApproval | null ;
15471548 pendingApprovals : PendingApproval [ ] ;
15481549 pendingUserInputs : PendingUserInput [ ] ;
1550+ /** Present only while the user is answering the active question. */
15491551 activePendingProgress : {
15501552 questionIndex : number ;
15511553 isLastQuestion : boolean ;
@@ -1557,6 +1559,7 @@ export interface ChatComposerProps {
15571559 allowCustomAnswer ?: boolean | undefined ;
15581560 } | null ;
15591561 } | null ;
1562+ onToggleAnsweringPendingUserInput : ( ) => void ;
15601563 activePendingResolvedAnswers : Record < string , unknown > | null ;
15611564 activePendingIsResponding : boolean ;
15621565 activePendingDraftAnswers : Record < string , PendingUserInputDraftAnswer > ;
@@ -1713,8 +1716,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
17131716 environmentUnavailable,
17141717 activePendingApproval,
17151718 pendingApprovals,
1716- pendingUserInputs,
1719+ pendingUserInputs : availablePendingUserInputs ,
17171720 activePendingProgress,
1721+ onToggleAnsweringPendingUserInput,
17181722 activePendingResolvedAnswers,
17191723 activePendingIsResponding,
17201724 activePendingDraftAnswers,
@@ -1791,6 +1795,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
17911795 const activeTasksProgress = shownSyncPhase === null ? props . activeTasksProgress : null ;
17921796 const activeTaskSteps = shownSyncPhase === null ? props . activeTaskSteps : null ;
17931797 const isEditingQueuedMessage = editingQueuedAttachments !== null ;
1798+ // The question panel shows every pending question; the editor, Send and
1799+ // attachments belong to a question only while the user is answering it.
1800+ const pendingUserInputs = activePendingProgress ? availablePendingUserInputs : [ ] ;
17941801 // ------------------------------------------------------------------
17951802 // Store subscriptions (prompt / images / terminal contexts)
17961803 // ------------------------------------------------------------------
@@ -2769,12 +2776,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
27692776 const isComposerApprovalState = activePendingApproval !== null ;
27702777 const composerSuggestionsVisible = composerMenuOpen && ! isComposerApprovalState ;
27712778 const composerSuggestionListVisible = composerSuggestionsVisible && composerMenuItems . length > 0 ;
2772- const activePendingUserInput = pendingUserInputs [ 0 ] ?? null ;
2779+ const activePendingUserInput = availablePendingUserInputs [ 0 ] ?? null ;
27732780 const isChoiceOnlyPendingQuestion =
27742781 activePendingProgress ?. activeQuestion ?. allowCustomAnswer === false ;
27752782 const showComposerTopDrawer =
27762783 isComposerApprovalState ||
2777- pendingUserInputs . length > 0 ||
2784+ availablePendingUserInputs . length > 0 ||
27782785 ( ! isComposerCollapsedMobile && showPlanFollowUpPrompt && activeProposedPlan !== null ) ;
27792786 const showCollapsedMobilePromptRow =
27802787 isComposerCollapsedMobile && ! isComposerApprovalState && pendingUserInputs . length === 0 ;
@@ -3386,18 +3393,24 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
33863393 requestId : string | null ;
33873394 questionId : string | null ;
33883395 } | null > ( null ) ;
3396+ // Where the message caret was when the user chose to answer a question.
3397+ const messageCaretBeforeAnsweringRef = useRef < { text : string ; cursor : number } | null > ( null ) ;
33893398
33903399 useEffect ( ( ) => {
33913400 const nextCustomAnswer = activePendingProgress ?. customAnswer ;
33923401 if ( typeof nextCustomAnswer !== "string" ) {
3393- // The question is gone and the editor shows the thread draft again. The
3394- // ref still holds the last answer text, and Send reads the ref. Place
3395- // the caret at the end so the next keystroke appends .
3402+ // The editor shows the thread draft again: the user went back to it, or
3403+ // the question is gone. The ref still holds the last answer text, and
3404+ // Send reads the ref. Return the caret to where the message was left .
33963405 if ( lastSyncedPendingInputRef . current !== null ) {
33973406 promptRef . current = prompt ;
3398- const { cursor, trigger } = composerStateAtPromptEnd ( prompt ) ;
3407+ const { cursor, trigger } = composerStateForReturningDraft (
3408+ prompt ,
3409+ messageCaretBeforeAnsweringRef . current ,
3410+ ) ;
33993411 setComposerCursor ( cursor ) ;
34003412 resetComposerTrigger ( trigger ) ;
3413+ messageCaretBeforeAnsweringRef . current = null ;
34013414 }
34023415 lastSyncedPendingInputRef . current = null ;
34033416 return ;
@@ -3849,6 +3862,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
38493862 } ;
38503863 } , [ composerCursor , promptRef ] ) ;
38513864
3865+ const toggleAnsweringPendingUserInput = useCallback ( ( ) => {
3866+ if ( ! activePendingProgress ) {
3867+ const { value, cursor } = readComposerSnapshot ( ) ;
3868+ messageCaretBeforeAnsweringRef . current = { text : value , cursor } ;
3869+ }
3870+ onToggleAnsweringPendingUserInput ( ) ;
3871+ } , [ activePendingProgress , onToggleAnsweringPendingUserInput , readComposerSnapshot ] ) ;
3872+
38523873 const resolveActiveComposerTrigger = useCallback ( ( ) : {
38533874 snapshot : { value : string ; cursor : number ; expandedCursor : number } ;
38543875 trigger : ComposerTrigger | null ;
@@ -4202,7 +4223,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
42024223 compactDisabled ||
42034224 noProviderAvailable ||
42044225 activePendingApproval !== null ||
4205- pendingUserInputs . length > 0 ||
4226+ availablePendingUserInputs . length > 0 ||
42064227 phase === "running" ||
42074228 isSendBusy ||
42084229 isConnecting ||
@@ -4214,12 +4235,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
42144235 } , [
42154236 activePendingApproval ,
42164237 activeThreadId ,
4238+ availablePendingUserInputs . length ,
42174239 compactDisabled ,
42184240 isConnecting ,
42194241 isSendBusy ,
42204242 noProviderAvailable ,
42214243 onCompactContext ,
4222- pendingUserInputs . length ,
42234244 phase ,
42244245 ] ) ;
42254246 const expandMobileComposer = useCallback ( ( ) => {
@@ -5029,7 +5050,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
50295050 } , [ ] ) ;
50305051 const hasBannerItems = props . bannerItems . length > 0 ;
50315052 const hasBlockingComposerTopDrawer =
5032- activePendingApproval !== null || pendingUserInputs . length > 0 ;
5053+ activePendingApproval !== null || availablePendingUserInputs . length > 0 ;
50335054 const showInlineTasksBadge =
50345055 activeTasksProgress !== null &&
50355056 activeTaskSteps !== null &&
@@ -6613,16 +6634,19 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
66136634 />
66146635 </ ComposerBanner . Actions >
66156636 </ ComposerBanner . Row >
6616- ) : ! isComposerCollapsedMobile && pendingUserInputs . length > 0 ? (
6637+ ) : availablePendingUserInputs . length > 0 &&
6638+ ( ! isComposerCollapsedMobile || ! activePendingProgress ) ? (
66176639 < ComposerPendingUserInputPanel
6618- pendingUserInputs = { pendingUserInputs }
6640+ pendingUserInputs = { availablePendingUserInputs }
66196641 respondingRequestIds = {
66206642 activePendingIsResponding && activePendingUserInput
66216643 ? [ ...respondingRequestIds , activePendingUserInput . requestId ]
66226644 : respondingRequestIds
66236645 }
66246646 answers = { activePendingDraftAnswers }
66256647 questionIndex = { activePendingQuestionIndex }
6648+ isAnswering = { activePendingProgress !== null }
6649+ onToggleAnswering = { toggleAnsweringPendingUserInput }
66266650 onToggleOption = { onSelectActivePendingUserInputOption }
66276651 onAdvance = { onAdvanceActivePendingUserInput }
66286652 onDismiss = { onDismissActivePendingUserInput }
@@ -6643,6 +6667,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
66436667 }
66446668 answers = { activePendingDraftAnswers }
66456669 questionIndex = { activePendingQuestionIndex }
6670+ isAnswering
6671+ onToggleAnswering = { toggleAnsweringPendingUserInput }
66466672 onToggleOption = { onSelectActivePendingUserInputOption }
66476673 onAdvance = { onAdvanceActivePendingUserInput }
66486674 onDismiss = { onDismissActivePendingUserInput }
@@ -7350,7 +7376,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
73507376 isComposerApprovalState ||
73517377 projectSelectionRequired ||
73527378 isChoiceOnlyPendingQuestion ||
7353- activePendingIsResponding
7379+ ( activePendingProgress !== null && activePendingIsResponding )
73547380 }
73557381 />
73567382 </ ComposerContextActionsContext >
0 commit comments