From baa788a95da46b14c00d114625a24ac8d0f1acab Mon Sep 17 00:00:00 2001 From: ahmedGaber93 Date: Mon, 18 Sep 2023 22:29:37 +0200 Subject: [PATCH 1/5] 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], ); /** From 124ec28aebd04d1df2f147e653dfc1a4922313d6 Mon Sep 17 00:00:00 2001 From: ahmedGaber93 Date: Mon, 18 Sep 2023 22:32:03 +0200 Subject: [PATCH 2/5] fix issue 27156 --- .../home/report/ReportActionCompose/ComposerWithSuggestions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js index 0f6ec912382f..14930a0c3ab1 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js @@ -190,7 +190,7 @@ function ComposerWithSuggestions({ // Reset suggestions when an emoji is replaced and the selection is not changed. // More info issue #27156 - if (selection.end === newSelectionPosition){ + if (selection.end === newSelectionPosition && suggestionsRef.current){ suggestionsRef.current.resetSuggestions(); } From a66f27cd4a89114324310659300173c99d1b0aaa Mon Sep 17 00:00:00 2001 From: ahmedGaber93 Date: Mon, 18 Sep 2023 23:04:14 +0200 Subject: [PATCH 3/5] lint and remove selection compare --- .../ComposerWithSuggestions.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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], ); /** From ff989cc0444a4a86a768e73a27cbd01f3c4fa2b9 Mon Sep 17 00:00:00 2001 From: ahmedGaber93 Date: Mon, 18 Sep 2023 23:10:54 +0200 Subject: [PATCH 4/5] prettier --- .../home/report/ReportActionCompose/ComposerWithSuggestions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js index 942d7d675408..46d69a763a15 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js @@ -187,7 +187,7 @@ function ComposerWithSuggestions({ if (commentValue !== newComment) { // 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){ + if (suggestionsRef.current) { suggestionsRef.current.resetSuggestions(); } From aa5f44fa7e2a7e0f9552e6d63cce89d576d3b4a4 Mon Sep 17 00:00:00 2001 From: ahmedGaber93 Date: Tue, 19 Sep 2023 16:24:55 +0200 Subject: [PATCH 5/5] improve comments --- .../home/report/ReportActionCompose/ComposerWithSuggestions.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js index 46d69a763a15..0257590908e8 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js @@ -185,8 +185,7 @@ function ComposerWithSuggestions({ setIsCommentEmpty(!!newComment.match(/^(\s)*$/)); setValue(newComment); if (commentValue !== newComment) { - // Reset emoji suggestions when an emoji is replaced. - // Important when emoji is replaced and the selection is not changed, more info issue #27156 + // Ensure emoji suggestions are hidden even when the selection is not changed (so calculateEmojiSuggestion would not be called). if (suggestionsRef.current) { suggestionsRef.current.resetSuggestions(); }