@@ -2548,7 +2548,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
25482548 activePendingProgress ?. customAnswer ,
25492549 activePendingProgress ?. activeQuestion ?. id ,
25502550 activePendingUserInput ?. requestId ,
2551- prompt ,
25522551 promptRef ,
25532552 ] ) ;
25542553
@@ -4315,6 +4314,89 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
43154314 setIsStashMenuOpen ( false ) ;
43164315 } , [ prompt ] ) ;
43174316
4317+ // The cursor is only needed as a fallback when the editor has no snapshot,
4318+ // so read it through a ref instead of re-binding the shortcut listener on
4319+ // every caret move.
4320+ const composerCursorRef = useRef ( composerCursor ) ;
4321+ composerCursorRef . current = composerCursor ;
4322+
4323+ const applyReasoningCycle = useCallback (
4324+ ( direction : "increase" | "decrease" ) => {
4325+ const editorShowsDraftPrompt = ! isComposerApprovalState && activePendingProgress === null ;
4326+ const currentPrompt = editorShowsDraftPrompt
4327+ ? promptRef . current
4328+ : ( getComposerDraft ( composerDraftTarget ) ?. prompt ?? "" ) ;
4329+ const currentModelOptions = composerModelOptions ?. [ selectedInstanceId ] ;
4330+ const transition = resolveReasoningTransition ( {
4331+ capabilities : getProviderModelCapabilities (
4332+ selectedProviderModels ,
4333+ selectedModel ,
4334+ selectedProvider ,
4335+ settings . planModeEnabled ,
4336+ ) ,
4337+ modelOptions : currentModelOptions ,
4338+ prompt : currentPrompt ,
4339+ action : { type : "cycle" , direction } ,
4340+ } ) ;
4341+ if ( transition . status === "blocked" ) {
4342+ toastManager . add ( {
4343+ type : "info" ,
4344+ title : "Remove “ultrathink” from the prompt text to change reasoning." ,
4345+ } ) ;
4346+ return ;
4347+ }
4348+ if ( transition . status === "unsupported" ) {
4349+ toastManager . add ( {
4350+ type : "info" ,
4351+ title : "This model has no reasoning levels to switch between." ,
4352+ } ) ;
4353+ return ;
4354+ }
4355+ if ( transition . status !== "changed" ) return ;
4356+ if ( transition . prompt !== currentPrompt ) {
4357+ setPrompt ( transition . prompt ) ;
4358+ // When a pending question or approval hides the editor, the draft
4359+ // is updated in the store only. The cursor and trigger belong to
4360+ // the visible editor state and are rebuilt when the draft returns.
4361+ if ( editorShowsDraftPrompt ) {
4362+ const currentExpandedCursor =
4363+ composerEditorRef . current ?. readSnapshot ( ) . expandedCursor ??
4364+ expandCollapsedComposerCursor ( currentPrompt , composerCursorRef . current ) ;
4365+ const nextExpandedCursor = mapComposerCursorAcrossLeadingPromptChange (
4366+ currentPrompt ,
4367+ transition . prompt ,
4368+ currentExpandedCursor ,
4369+ ) ;
4370+ promptRef . current = transition . prompt ;
4371+ setComposerCursor ( collapseExpandedComposerCursor ( transition . prompt , nextExpandedCursor ) ) ;
4372+ setComposerTrigger ( detectComposerTrigger ( transition . prompt , nextExpandedCursor ) ) ;
4373+ }
4374+ }
4375+ if ( transition . modelOptions !== currentModelOptions ) {
4376+ setProviderModelOptions ( composerDraftTarget , selectedProvider , transition . modelOptions , {
4377+ instanceId : selectedInstanceId ,
4378+ model : selectedModel ,
4379+ persistSticky : true ,
4380+ } ) ;
4381+ }
4382+ } ,
4383+ [
4384+ activePendingProgress ,
4385+ composerDraftTarget ,
4386+ composerModelOptions ,
4387+ getComposerDraft ,
4388+ isComposerApprovalState ,
4389+ promptRef ,
4390+ selectedInstanceId ,
4391+ selectedModel ,
4392+ selectedProvider ,
4393+ selectedProviderModels ,
4394+ setPrompt ,
4395+ setProviderModelOptions ,
4396+ settings . planModeEnabled ,
4397+ ] ,
4398+ ) ;
4399+
43184400 useEffect ( ( ) => {
43194401 const handler = ( event : globalThis . KeyboardEvent ) => {
43204402 const command = resolveShortcutCommand ( event , keybindings , {
@@ -4335,67 +4417,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
43354417 return ;
43364418 }
43374419 if ( reasoningDirection !== null ) {
4338- const editorShowsDraftPrompt = ! isComposerApprovalState && activePendingProgress === null ;
4339- const currentPrompt = editorShowsDraftPrompt
4340- ? promptRef . current
4341- : ( getComposerDraft ( composerDraftTarget ) ?. prompt ?? "" ) ;
4342- const currentModelOptions = composerModelOptions ?. [ selectedInstanceId ] ;
4343- const transition = resolveReasoningTransition ( {
4344- capabilities : getProviderModelCapabilities (
4345- selectedProviderModels ,
4346- selectedModel ,
4347- selectedProvider ,
4348- settings . planModeEnabled ,
4349- ) ,
4350- modelOptions : currentModelOptions ,
4351- prompt : currentPrompt ,
4352- action : { type : "cycle" , direction : reasoningDirection } ,
4353- } ) ;
4354- if ( transition . status === "changed" ) {
4355- if ( transition . prompt !== currentPrompt ) {
4356- setPrompt ( transition . prompt ) ;
4357- // When a pending question or approval hides the editor, the draft
4358- // is updated in the store only. The cursor and trigger belong to
4359- // the visible editor state and are rebuilt when the draft returns.
4360- if ( editorShowsDraftPrompt ) {
4361- const currentExpandedCursor =
4362- composerEditorRef . current ?. readSnapshot ( ) . expandedCursor ??
4363- expandCollapsedComposerCursor ( currentPrompt , composerCursor ) ;
4364- const nextExpandedCursor = mapComposerCursorAcrossLeadingPromptChange (
4365- currentPrompt ,
4366- transition . prompt ,
4367- currentExpandedCursor ,
4368- ) ;
4369- promptRef . current = transition . prompt ;
4370- setComposerCursor (
4371- collapseExpandedComposerCursor ( transition . prompt , nextExpandedCursor ) ,
4372- ) ;
4373- setComposerTrigger ( detectComposerTrigger ( transition . prompt , nextExpandedCursor ) ) ;
4374- }
4375- }
4376- if ( transition . modelOptions !== currentModelOptions ) {
4377- setProviderModelOptions (
4378- composerDraftTarget ,
4379- selectedProvider ,
4380- transition . modelOptions ,
4381- {
4382- instanceId : selectedInstanceId ,
4383- model : selectedModel ,
4384- persistSticky : true ,
4385- } ,
4386- ) ;
4387- }
4388- } else if ( transition . status === "blocked" ) {
4389- toastManager . add ( {
4390- type : "info" ,
4391- title : "Remove “ultrathink” from the prompt text to change reasoning." ,
4392- } ) ;
4393- } else if ( transition . status === "unsupported" ) {
4394- toastManager . add ( {
4395- type : "info" ,
4396- title : "This model does not advertise reasoning levels." ,
4397- } ) ;
4398- }
4420+ applyReasoningCycle ( reasoningDirection ) ;
43994421 return ;
44004422 }
44014423 if ( pendingUserInputs . length > 0 && ! isComposerApprovalState ) {
@@ -4411,22 +4433,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
44114433 return ( ) => window . removeEventListener ( "keydown" , handler , true ) ;
44124434 } , [
44134435 activePendingProgress ,
4414- composerDraftTarget ,
4415- composerCursor ,
4416- composerModelOptions ,
4417- getComposerDraft ,
4436+ applyReasoningCycle ,
44184437 isComposerApprovalState ,
44194438 isComposerModelPickerOpen ,
44204439 keybindings ,
44214440 pendingUserInputs . length ,
44224441 projectSelectionRequired ,
4423- selectedInstanceId ,
4424- selectedModel ,
4425- selectedProvider ,
4426- selectedProviderModels ,
4427- setPrompt ,
4428- setProviderModelOptions ,
4429- settings . planModeEnabled ,
44304442 stashCurrentPrompt ,
44314443 terminalOpen ,
44324444 ] ) ;
0 commit comments