diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js index 14930a0c3ab1..942d7d675408 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js @@ -185,18 +185,16 @@ function ComposerWithSuggestions({ setIsCommentEmpty(!!newComment.match(/^(\s)*$/)); setValue(newComment); if (commentValue !== newComment) { - const remainder = ComposerUtils.getCommonSuffixLength(commentRef.current, newComment); - const newSelectionPosition = newComment.length - remainder; - - // Reset suggestions when an emoji is replaced and the selection is not changed. - // More info issue #27156 - if (selection.end === newSelectionPosition && suggestionsRef.current){ + // Reset emoji suggestions when an emoji is replaced. + // Important when emoji is replaced and the selection is not changed, more info issue #27156 + if (suggestionsRef.current){ suggestionsRef.current.resetSuggestions(); } + const remainder = ComposerUtils.getCommonSuffixLength(commentRef.current, newComment); setSelection({ - start: newSelectionPosition, - end: newSelectionPosition, + start: newComment.length - remainder, + end: newComment.length - remainder, }); } @@ -220,7 +218,7 @@ function ComposerWithSuggestions({ debouncedBroadcastUserIsTyping(reportID); } }, - [selection.end, debouncedUpdateFrequentlyUsedEmojis, preferredLocale, preferredSkinTone, reportID, setIsCommentEmpty], + [debouncedUpdateFrequentlyUsedEmojis, preferredLocale, preferredSkinTone, reportID, setIsCommentEmpty, suggestionsRef], ); /**