From fcc8e2ac9d5bb42052874d2454e2a9791c6f036d Mon Sep 17 00:00:00 2001 From: "Sahil (via MelvinBot)" Date: Tue, 7 Jul 2026 16:02:19 +0000 Subject: [PATCH 1/2] Fix: copy only the selected text for system messages Co-authored-by: Sahil --- .../inbox/report/ContextMenu/ContextMenuActions.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx index fc56df3582ea..51998630898f 100644 --- a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx @@ -927,7 +927,16 @@ 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"). + setClipboardMessage( + selection.replaceAll(/()(.*?)(<\/mention-user>)/gi, (match, openTag: string, innerContent: string, closeTag: string): string => { + const modifiedContent = Str.removeSMSDomain(innerContent) || ''; + return openTag + modifiedContent + closeTag || ''; + }), + ); + } else if (isReportPreviewAction) { const iouReportID = getIOUReportIDFromReportActionPreview(reportAction); const displayMessage = getReportPreviewMessage({ reportOrID: iouReportID, From 3b23fb3baf8d90bb52eedbdfdea1a5829a17dab8 Mon Sep 17 00:00:00 2001 From: "Sahil (via MelvinBot)" Date: Wed, 8 Jul 2026 06:03:29 +0000 Subject: [PATCH 2/2] Extract shared mention-cleanup helper for clipboard copy Co-authored-by: Sahil --- .../report/ContextMenu/ContextMenuActions.tsx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx index 51998630898f..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; @@ -930,12 +940,7 @@ const ContextMenuActions: ContextMenuAction[] = [ 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"). - setClipboardMessage( - selection.replaceAll(/()(.*?)(<\/mention-user>)/gi, (match, openTag: string, innerContent: string, closeTag: string): string => { - const modifiedContent = Str.removeSMSDomain(innerContent) || ''; - return openTag + modifiedContent + closeTag || ''; - }), - ); + setClipboardMessageWithCleanedMentions(selection); } else if (isReportPreviewAction) { const iouReportID = getIOUReportIDFromReportActionPreview(reportAction); const displayMessage = getReportPreviewMessage({ @@ -1327,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) {