From 6d75fab69b1dd0c5f67dbb3b04208b1e8289e5e2 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Fri, 23 May 2025 16:25:08 +0530 Subject: [PATCH 1/2] fix: ComposeBox - When you click on the mention again, extra characters appear. Signed-off-by: krishna2323 --- src/CONST.ts | 3 ++- .../ReportActionCompose/SuggestionMention.tsx | 22 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 65934582b69c..7e32ea05b2fa 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3538,6 +3538,7 @@ const CONST = { EMPTY_COMMENT: /^(\s)*$/, SPECIAL_CHAR: /[,/?"{}[\]()&^%;`$=#<>!*]/g, FIRST_SPACE: /.+?(?=\s)/, + SPECIAL_CHAR_MENTION_BREAKER: /[,/?"{}[\]()&^%;`$=<>!*]/g, get SPECIAL_CHAR_OR_EMOJI() { return new RegExp(`[~\\n\\s]|(_\\b(?!$))|${this.SPECIAL_CHAR.source}|${this.EMOJI.source}`, 'gu'); @@ -3550,7 +3551,7 @@ const CONST = { // Define the regular expression pattern to find a potential end of a mention suggestion: // It might be a space, a newline character, an emoji, or a special character (excluding underscores & tildes, which might be used in usernames) get MENTION_BREAKER() { - return new RegExp(`[\\n\\s]|${this.SPECIAL_CHAR.source}|${this.EMOJI.source}`, 'gu'); + return new RegExp(`[\\n\\s]|${this.SPECIAL_CHAR_MENTION_BREAKER.source}|${this.EMOJI.source}`, 'gu'); }, get ALL_EMOJIS() { diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx index 92bed91f2930..fecabe820ba3 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx @@ -190,6 +190,14 @@ function SuggestionMention( [formatLoginPrivateDomain], ); + function getOriginalMentionText(inputValue: string, atSignIndex: number) { + const rest = inputValue.slice(atSignIndex); + + const breakerIndex = rest.search(CONST.REGEX.MENTION_BREAKER); + + // If no breaker is found, return the entire rest of the string + return breakerIndex === -1 ? rest : rest.slice(0, breakerIndex); + } /** * Replace the code of mention and update selection */ @@ -201,7 +209,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; @@ -216,16 +225,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 b0ef9e071b64029590611a696995a444bfdb989c Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Fri, 23 May 2025 21:17:32 +0530 Subject: [PATCH 2/2] 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 fecabe820ba3..16e5439219ed 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;