Skip to content
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
23 changes: 16 additions & 7 deletions src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>)(.*?)(<\/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<ReportAction>;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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>)(.*?)(<\/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) {
Expand Down
Loading