diff --git a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx index fc56df3582ea..6ca9df4815b4 100644 --- a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx @@ -266,6 +266,16 @@ function setClipboardMessage(content: string | undefined) { } } +/** Sets the HTML string to Clipboard after stripping the SMS domain from any user mentions */ +function setClipboardMessageWithCleanedMentions(value: string) { + setClipboardMessage( + value.replaceAll(/()(.*?)(<\/mention-user>)/gi, (match, openTag: string, innerContent: string, closeTag: string): string => { + const modifiedContent = Str.removeSMSDomain(innerContent) || ''; + return openTag + modifiedContent + closeTag || ''; + }), + ); +} + type ShouldShow = (args: { type: string; reportAction: OnyxEntry; @@ -927,7 +937,11 @@ const ContextMenuActions: ContextMenuAction[] = [ const isAttachment = isReportActionAttachment(reportAction); if (!isAttachment) { const content = selection || messageHtml; - if (isReportPreviewAction) { + if (selection) { + // When the user has highlighted part of a message, always copy exactly what's selected, + // regardless of the report action type (including system messages like "marked as paid"). + setClipboardMessageWithCleanedMentions(selection); + } else if (isReportPreviewAction) { const iouReportID = getIOUReportIDFromReportActionPreview(reportAction); const displayMessage = getReportPreviewMessage({ reportOrID: iouReportID, @@ -1318,12 +1332,7 @@ const ContextMenuActions: ContextMenuAction[] = [ const missingFields = getOriginalMessage(reportAction)?.missingFields; setClipboardMessage(translate('violations.smartscanFailed', {canEdit: wasActionTakenByCurrentUser(iouAction), missingFields})); } else if (content) { - setClipboardMessage( - content.replaceAll(/()(.*?)(<\/mention-user>)/gi, (match, openTag: string, innerContent: string, closeTag: string): string => { - const modifiedContent = Str.removeSMSDomain(innerContent) || ''; - return openTag + modifiedContent + closeTag || ''; - }), - ); + setClipboardMessageWithCleanedMentions(content); } else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.SETTLEMENT_ACCOUNT_LOCKED)) { setClipboardMessage(getSettlementAccountLockedMessage(translate, reportAction)); } else if (messageText) {