Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3538,6 +3538,7 @@ const CONST = {
EMPTY_COMMENT: /^(\s)*$/,
SPECIAL_CHAR: /[,/?"{}[\]()&^%;`$=#<>!*]/g,
FIRST_SPACE: /.+?(?=\s)/,
SPECIAL_CHAR_MENTION_BREAKER: /[,/?"{}[\]()&^%;`$=<>!*]/g,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the preview PR, we were using SPECIAL_CHAR which counts # as the end of the mention. However, we can add mentions using both @ and #, so we need to create a new regex for the mention breaker to resolve #61961.


get SPECIAL_CHAR_OR_EMOJI() {
return new RegExp(`[~\\n\\s]|(_\\b(?!$))|${this.SPECIAL_CHAR.source}|${this.EMOJI.source}`, 'gu');
Expand All @@ -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() {
Expand Down
24 changes: 12 additions & 12 deletions src/pages/home/report/ReportActionCompose/SuggestionMention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand All @@ -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;
Expand All @@ -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],
);

/**
Expand Down
Loading