@@ -116,31 +116,22 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
116116
117117 if ( message . type === "enhancedPrompt" ) {
118118 if ( message . text && textAreaRef . current ) {
119- // Use native browser methods to preserve undo stack
120- const textarea = textAreaRef . current
121-
122- // Focus the textarea to ensure it's the active element
123- textarea . focus ( )
124-
125- // Select all text first
126- textarea . select ( )
127-
128119 try {
129120 // Use execCommand to replace text while preserving undo history
130121 if ( document . execCommand ) {
122+ // Use native browser methods to preserve undo stack
123+ const textarea = textAreaRef . current
124+
125+ // Focus the textarea to ensure it's the active element
126+ textarea . focus ( )
127+
128+ // Select all text first
129+ textarea . select ( )
131130 document . execCommand ( "insertText" , false , message . text )
132131 } else {
133- // Fallback for browsers that don't support execCommand
134- // This approach also preserves undo history in modern browsers
135- textarea . setRangeText ( message . text , 0 , textarea . value . length , "select" )
136-
137- // Trigger input event to notify React of the change
138- const inputEvent = new Event ( "input" , { bubbles : true } )
139- textarea . dispatchEvent ( inputEvent )
132+ setInputValue ( message . text )
140133 }
141- } catch ( error ) {
142- // Fallback to direct value assignment if native methods fail
143- console . warn ( "Native text replacement failed, falling back to direct assignment:" , error )
134+ } catch {
144135 setInputValue ( message . text )
145136 }
146137 }
0 commit comments