From 40d3c4b3119585b133166a042b8cee8e49ebce5f Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sun, 4 May 2025 01:30:00 +0530 Subject: [PATCH 1/4] fix: ComposeBox - When you click on the mention again, extra characters appear. Signed-off-by: krishna2323 --- .../ReportActionCompose/SuggestionMention.tsx | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx index 92bed91f2930..bf7b7f102c0b 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx @@ -190,6 +190,12 @@ function SuggestionMention( [formatLoginPrivateDomain], ); + function getOriginalMentionText(inputValue: string, atSignIndex: number) { + const rest = inputValue.slice(atSignIndex); + const mentionMatch = rest.match(/^[@\w.\-+]+/); // capture till space or special characters not in emails + return mentionMatch?.[0] ?? ''; + } + /** * Replace the code of mention and update selection */ @@ -201,8 +207,8 @@ function SuggestionMention( return; } const mentionCode = getMentionCode(mentionObject, suggestionValues.prefixType); - const commentAfterMention = value.slice(suggestionValues.atSignIndex + suggestionValues.mentionPrefix.length + 1); - + const originalMention = getOriginalMentionText(value, suggestionValues.atSignIndex); + const commentAfterMention = value.slice(suggestionValues.atSignIndex + originalMention.length); updateComment(`${commentBeforeAtSign}${mentionCode} ${trimLeadingSpace(commentAfterMention)}`, true); const selectionPosition = suggestionValues.atSignIndex + mentionCode.length + CONST.SPACE_LENGTH; setSelection({ @@ -216,16 +222,7 @@ function SuggestionMention( shouldShowSuggestionMenu: false, })); }, - [ - value, - suggestionValues.atSignIndex, - suggestionValues.suggestedMentions, - suggestionValues.prefixType, - suggestionValues.mentionPrefix.length, - getMentionCode, - updateComment, - setSelection, - ], + [value, suggestionValues.atSignIndex, suggestionValues.suggestedMentions, suggestionValues.prefixType, getMentionCode, updateComment, setSelection], ); /** From 4f63be91ae284f87911fd562b3923738b7b525c0 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sun, 4 May 2025 01:37:50 +0530 Subject: [PATCH 2/4] fix ESLint. Signed-off-by: krishna2323 --- src/pages/home/report/ReportActionCompose/SuggestionMention.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx index bf7b7f102c0b..674780c8e3a0 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx @@ -92,7 +92,7 @@ function SuggestionMention( // eslint-disable-next-line react-compiler/react-compiler suggestionValuesRef.current = suggestionValues; - const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); + const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const isMentionSuggestionsMenuVisible = !!suggestionValues.suggestedMentions.length && suggestionValues.shouldShowSuggestionMenu; From 2f8b90353db246a09566ccde5d0f1f847af47fce Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Thu, 8 May 2025 10:21:22 +0530 Subject: [PATCH 3/4] use CONST.REGEX.MENTION_BREAKER. Signed-off-by: krishna2323 --- .../report/ReportActionCompose/SuggestionMention.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx index 674780c8e3a0..be4b57334b6d 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx @@ -192,8 +192,14 @@ function SuggestionMention( function getOriginalMentionText(inputValue: string, atSignIndex: number) { const rest = inputValue.slice(atSignIndex); - const mentionMatch = rest.match(/^[@\w.\-+]+/); // capture till space or special characters not in emails - return mentionMatch?.[0] ?? ''; + const breakerMatch = rest.match(CONST.REGEX.MENTION_BREAKER); + const breakerIndex = breakerMatch ? rest.search(CONST.REGEX.MENTION_BREAKER) : -1; + + if (breakerIndex === -1) { + return rest; // No breaker found, whole rest is the mention + } + + return rest.slice(0, breakerIndex); } /** From ef5c749560d3c455c72c8716c584c4520c34b7f8 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Fri, 9 May 2025 14:43:28 +0530 Subject: [PATCH 4/4] update getOriginalMentionText to only use search for regex match. Signed-off-by: krishna2323 --- .../report/ReportActionCompose/SuggestionMention.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx index be4b57334b6d..a1cce552fd65 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx @@ -192,14 +192,11 @@ function SuggestionMention( function getOriginalMentionText(inputValue: string, atSignIndex: number) { const rest = inputValue.slice(atSignIndex); - const breakerMatch = rest.match(CONST.REGEX.MENTION_BREAKER); - const breakerIndex = breakerMatch ? rest.search(CONST.REGEX.MENTION_BREAKER) : -1; - if (breakerIndex === -1) { - return rest; // No breaker found, whole rest is the mention - } + const breakerIndex = rest.search(CONST.REGEX.MENTION_BREAKER); - return rest.slice(0, breakerIndex); + // If no breaker is found, return the entire rest of the string + return breakerIndex === -1 ? rest : rest.slice(0, breakerIndex); } /**