@@ -494,10 +494,10 @@ export function UserInput({
494494 [ handleSubmit , mentionTokensWithContext , value , textareaRef ]
495495 )
496496
497- const startRecognition = useCallback ( ( ) => {
497+ const startRecognition = useCallback ( ( ) : boolean => {
498498 const w = window as WindowWithSpeech
499499 const SpeechRecognitionAPI = w . SpeechRecognition || w . webkitSpeechRecognition
500- if ( ! SpeechRecognitionAPI ) return
500+ if ( ! SpeechRecognitionAPI ) return false
501501
502502 const recognition = new SpeechRecognitionAPI ( )
503503 recognition . continuous = true
@@ -538,9 +538,10 @@ export function UserInput({
538538 recognitionRef . current = recognition
539539 try {
540540 recognition . start ( )
541+ return true
541542 } catch {
542543 recognitionRef . current = null
543- setIsListening ( false )
544+ return false
544545 }
545546 } , [ ] )
546547
@@ -564,34 +565,38 @@ export function UserInput({
564565 }
565566
566567 prefixRef . current = value
567- startRecognition ( )
568- setIsListening ( true )
568+ if ( startRecognition ( ) ) {
569+ setIsListening ( true )
570+ }
569571 } , [ isListening , value , startRecognition ] )
570572
571- const handleInputChange = useCallback ( ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
572- const newValue = e . target . value
573- const caret = e . target . selectionStart ?? newValue . length
574-
575- if (
576- caret > 0 &&
577- newValue . charAt ( caret - 1 ) === '@' &&
578- ( caret === 1 || / \s / . test ( newValue . charAt ( caret - 2 ) ) )
579- ) {
580- const before = newValue . slice ( 0 , caret - 1 )
581- const after = newValue . slice ( caret )
582- const adjusted = `${ before } ${ after } `
583- setValue ( adjusted )
584- atInsertPosRef . current = caret - 1
585- setPlusMenuOpen ( true )
586- setPlusMenuSearch ( '' )
587- setPlusMenuActiveIndex ( 0 )
588- restartRecognition ( adjusted )
589- return
590- }
573+ const handleInputChange = useCallback (
574+ ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
575+ const newValue = e . target . value
576+ const caret = e . target . selectionStart ?? newValue . length
577+
578+ if (
579+ caret > 0 &&
580+ newValue . charAt ( caret - 1 ) === '@' &&
581+ ( caret === 1 || / \s / . test ( newValue . charAt ( caret - 2 ) ) )
582+ ) {
583+ const before = newValue . slice ( 0 , caret - 1 )
584+ const after = newValue . slice ( caret )
585+ const adjusted = `${ before } ${ after } `
586+ setValue ( adjusted )
587+ atInsertPosRef . current = caret - 1
588+ setPlusMenuOpen ( true )
589+ setPlusMenuSearch ( '' )
590+ setPlusMenuActiveIndex ( 0 )
591+ restartRecognition ( adjusted )
592+ return
593+ }
591594
592- setValue ( newValue )
593- restartRecognition ( newValue )
594- } , [ restartRecognition ] )
595+ setValue ( newValue )
596+ restartRecognition ( newValue )
597+ } ,
598+ [ restartRecognition ]
599+ )
595600
596601 const handleSelectAdjust = useCallback ( ( ) => {
597602 const textarea = textareaRef . current
0 commit comments