diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index bc2931f1c7009..3c4b441bc9c0a 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -811,6 +811,21 @@ function ComposerWithSuggestions({ onFocus(); }, [onFocus, setUpComposeFocusManager]); + // When using the suggestions box (Suggestions) we need to imperatively + // set the cursor to the end of the suggestion/mention after it's selected. + const onSuggestionSelected = useCallback((suggestionSelection: TextSelection) => { + const endOfSuggestionSelection = suggestionSelection.end; + setSelection(suggestionSelection); + + if (endOfSuggestionSelection === undefined) { + return; + } + + queueMicrotask(() => { + textInputRef.current?.setSelection?.(endOfSuggestionSelection, endOfSuggestionSelection); + }); + }, []); + return ( <>