From baa788a95da46b14c00d114625a24ac8d0f1acab Mon Sep 17 00:00:00 2001 From: ahmedGaber93 Date: Mon, 18 Sep 2023 22:29:37 +0200 Subject: [PATCH] fix issue 27156 --- .../ReportActionCompose/ComposerWithSuggestions.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js index 04757b0ff276..0f6ec912382f 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js @@ -186,9 +186,17 @@ function ComposerWithSuggestions({ 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.resetSuggestions(); + } + setSelection({ - start: newComment.length - remainder, - end: newComment.length - remainder, + start: newSelectionPosition, + end: newSelectionPosition, }); } @@ -212,7 +220,7 @@ function ComposerWithSuggestions({ debouncedBroadcastUserIsTyping(reportID); } }, - [debouncedUpdateFrequentlyUsedEmojis, preferredLocale, preferredSkinTone, reportID, setIsCommentEmpty], + [selection.end, debouncedUpdateFrequentlyUsedEmojis, preferredLocale, preferredSkinTone, reportID, setIsCommentEmpty], ); /**