Skip to content

fix: ComposeBox - When you click on the mention again, extra characters appear. #61362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 12, 2025
Merged
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
26 changes: 13 additions & 13 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,15 @@ 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,8 +210,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({
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],
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it have a lint issue if we use previous style? I prefer spread in multiple line as previously, it makes code cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so, because printWidth is set to 190 and this line only includes 157 characters.

printWidth: 190,

);

/**
Expand Down
Loading