From 998859d53e2855ae14349e49cc6b94f91fabe595 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Mon, 3 Jun 2024 19:21:10 +0800 Subject: [PATCH 1/4] clear syncSelectionWithOnChangeTextRef when updating message --- .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 5c203520148d..4c411916dafa 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -406,6 +406,9 @@ function ComposerWithSuggestions( */ const updateComment = useCallback( (commentValue: string, shouldDebounceSaveComment?: boolean) => { + if (isIOSNative) { + syncSelectionWithOnChangeTextRef.current = null; + } raiseIsScrollLikelyLayoutTriggered(); const {startIndex, endIndex, diff} = findNewlyAddedChars(lastTextRef.current, commentValue); const isEmojiInserted = diff.length && endIndex > startIndex && diff.trim() === diff && EmojiUtils.containsOnlyEmojis(diff); From 65be6975c53794d20b889e87534d5117b952cf53 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 4 Jun 2024 13:37:19 +0800 Subject: [PATCH 2/4] remove clearing syncSelectionWithOnChangeTextRef --- .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 4c411916dafa..5c203520148d 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -406,9 +406,6 @@ function ComposerWithSuggestions( */ const updateComment = useCallback( (commentValue: string, shouldDebounceSaveComment?: boolean) => { - if (isIOSNative) { - syncSelectionWithOnChangeTextRef.current = null; - } raiseIsScrollLikelyLayoutTriggered(); const {startIndex, endIndex, diff} = findNewlyAddedChars(lastTextRef.current, commentValue); const isEmojiInserted = diff.length && endIndex > startIndex && diff.trim() === diff && EmojiUtils.containsOnlyEmojis(diff); From bf75e3326a59ef1c2491438fd88a3fe0d3dc3e6a Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 4 Jun 2024 13:38:24 +0800 Subject: [PATCH 3/4] set syncSelectionWithOnChangeTextRef only if the new comment doesn't match the converted comment with space inserted --- .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 5c203520148d..13d6a311256d 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -409,11 +409,12 @@ function ComposerWithSuggestions( raiseIsScrollLikelyLayoutTriggered(); const {startIndex, endIndex, diff} = findNewlyAddedChars(lastTextRef.current, commentValue); const isEmojiInserted = diff.length && endIndex > startIndex && diff.trim() === diff && EmojiUtils.containsOnlyEmojis(diff); + const commentWithSpaceInserted = isEmojiInserted ? ComposerUtils.insertWhiteSpaceAtIndex(commentValue, endIndex) : commentValue; const { text: newComment, emojis, cursorPosition, - } = EmojiUtils.replaceAndExtractEmojis(isEmojiInserted ? ComposerUtils.insertWhiteSpaceAtIndex(commentValue, endIndex) : commentValue, preferredSkinTone, preferredLocale); + } = EmojiUtils.replaceAndExtractEmojis(commentWithSpaceInserted, preferredSkinTone, preferredLocale); if (emojis.length) { const newEmojis = EmojiUtils.getAddedEmojis(emojis, emojisPresentBefore.current); if (newEmojis.length) { @@ -438,7 +439,7 @@ function ComposerWithSuggestions( if (commentValue !== newComment) { const position = Math.max(selection.end + (newComment.length - commentRef.current.length), cursorPosition ?? 0); - if (isIOSNative) { + if (commentWithSpaceInserted !== newComment && isIOSNative) { syncSelectionWithOnChangeTextRef.current = {position, value: newComment}; } From 99d401e4b42e70d2beb127453a2973466c012310 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 4 Jun 2024 13:47:17 +0800 Subject: [PATCH 4/4] prettier --- .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 13d6a311256d..cf47fb7bab7c 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -410,11 +410,7 @@ function ComposerWithSuggestions( const {startIndex, endIndex, diff} = findNewlyAddedChars(lastTextRef.current, commentValue); const isEmojiInserted = diff.length && endIndex > startIndex && diff.trim() === diff && EmojiUtils.containsOnlyEmojis(diff); const commentWithSpaceInserted = isEmojiInserted ? ComposerUtils.insertWhiteSpaceAtIndex(commentValue, endIndex) : commentValue; - const { - text: newComment, - emojis, - cursorPosition, - } = EmojiUtils.replaceAndExtractEmojis(commentWithSpaceInserted, preferredSkinTone, preferredLocale); + const {text: newComment, emojis, cursorPosition} = EmojiUtils.replaceAndExtractEmojis(commentWithSpaceInserted, preferredSkinTone, preferredLocale); if (emojis.length) { const newEmojis = EmojiUtils.getAddedEmojis(emojis, emojisPresentBefore.current); if (newEmojis.length) {