@@ -983,6 +983,7 @@ import {
983983} from "@t3tools/client-runtime/providerSkills" ;
984984import { searchProviderSkills } from "../../providerSkillSearch" ;
985985import { useDelayedStatus } from "../../hooks/useDelayedStatus" ;
986+ import { useUpdateClientSettings } from "../../hooks/useSettings" ;
986987import { useMediaQuery } from "../../hooks/useMediaQuery" ;
987988import { usePanelAnimationSettings } from "../../panelAnimations" ;
988989import { useAtomCommand } from "../../state/use-atom-command" ;
@@ -2140,6 +2141,17 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
21402141 const hasWrappedPrompt = useComposerMultilinePrompt ( composerMenuAnchor ) ;
21412142 const hasMultilinePrompt = prompt . includes ( "\n" ) || hasWrappedPrompt ;
21422143 const [ isStashMenuOpen , setIsStashMenuOpen ] = useState ( false ) ;
2144+ const updateClientSettings = useUpdateClientSettings ( ) ;
2145+ // Flipping the setting remounts the editor, which drops focus. The flag
2146+ // tells the new instance that the user asked for this from the composer's
2147+ // shortcut and wants the caret back; changing the same setting from
2148+ // Settings leaves it alone. Rich text is a client setting rather than
2149+ // composer state, so both entry points drive the same switch.
2150+ const [ pendingComposerFocusRestore , setPendingComposerFocusRestore ] = useState ( false ) ;
2151+ const toggleComposerRichText = useCallback ( ( ) => {
2152+ setPendingComposerFocusRestore ( true ) ;
2153+ void updateClientSettings ( { composerRichTextEnabled : ! settings . composerRichTextEnabled } ) ;
2154+ } , [ settings . composerRichTextEnabled , updateClientSettings ] ) ;
21432155 const [ isTasksDrawerOpen , setIsTasksDrawerOpen ] = useState ( false ) ;
21442156 const [ stashPulse , setStashPulse ] = useState < { key : number ; active : boolean } > ( {
21452157 key : 0 ,
@@ -5217,6 +5229,28 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
52175229 setIsStashMenuOpen ( false ) ;
52185230 } , [ prompt ] ) ;
52195231
5232+ // The composer's own way to flip rich text, so the caret comes back after
5233+ // the remount. The Settings panel flips the same setting without a restore.
5234+ useEffect ( ( ) => {
5235+ const handler = ( event : globalThis . KeyboardEvent ) => {
5236+ const command = resolveShortcutCommand ( event , keybindings , {
5237+ context : {
5238+ terminalFocus : getTerminalFocusOwner ( ) !== null ,
5239+ terminalOpen,
5240+ modelPickerOpen : isComposerModelPickerOpen ,
5241+ } ,
5242+ } ) ;
5243+ if ( command !== "composer.toggleRichText" ) return ;
5244+ event . preventDefault ( ) ;
5245+ event . stopPropagation ( ) ;
5246+ // A held key auto-repeats keydown; one press is one flip.
5247+ if ( event . repeat || isCommandPaletteOpen ( ) ) return ;
5248+ toggleComposerRichText ( ) ;
5249+ } ;
5250+ window . addEventListener ( "keydown" , handler , true ) ;
5251+ return ( ) => window . removeEventListener ( "keydown" , handler , true ) ;
5252+ } , [ isComposerModelPickerOpen , keybindings , terminalOpen , toggleComposerRichText ] ) ;
5253+
52205254 useEffect ( ( ) => {
52215255 const handler = ( event : globalThis . KeyboardEvent ) => {
52225256 const command = resolveShortcutCommand ( event , keybindings , {
@@ -6877,6 +6911,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
68776911 }
68786912 editorRef = { composerEditorRef }
68796913 richTextEnabled = { settings . composerRichTextEnabled }
6914+ restoreFocusOnMount = { pendingComposerFocusRestore }
6915+ onFocusRestored = { ( ) => setPendingComposerFocusRestore ( false ) }
68806916 value = {
68816917 isComposerApprovalState
68826918 ? ""
0 commit comments