Skip to content

Fix: copy only the selected text for system messages#95517

Merged
flodnv merged 2 commits into
mainfrom
claude-copySelectionForSystemMessages
Jul 8, 2026
Merged

Fix: copy only the selected text for system messages#95517
flodnv merged 2 commits into
mainfrom
claude-copySelectionForSystemMessages

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

When copying a message via the context menu, system messages (e.g. "marked as paid", approved, reimbursed) always copied the full reconstructed message text, even when the user had only highlighted part of it. Regular chat messages, by contrast, already copied just the highlighted selection.

The copy handler captured the highlighted text into content = selection || messageHtml but only honored it in the fallback else if (content) branch at the bottom of a long if / else if chain. System messages match dedicated earlier branches that rebuild the whole message from the report action and never look at selection, so partial selections were ignored for them.

This was surfaced (not introduced) by #92142, which made system-message text selectable on desktop web — before that, users couldn't produce a partial selection for those actions.

The fix adds an early if (selection) guard at the top of the dispatch chain: when the user has highlighted part of any message, we copy exactly what's selected (reusing the same mention-cleanup already applied in the fallback branch). Full-message reconstruction remains the default when nothing is selected. This makes Step 8 and Step 10 in the report behave identically.

Fixed Issues

$ #95463
PROPOSAL: #95463 (comment)

Tests

// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review".
// Please describe what tests you performed that validates your changes worked.

  1. Go to a workspace chat and create an expense.
  2. Submit, approve, and mark the expense as paid so a "marked as paid" system message appears.
  3. Select just the word "marked" in that system message, right click > Copy to clipboard.
  4. Paste into the composer and verify only "marked" is pasted (not the full "marked as paid" message).
  5. Repeat with a partial selection on a regular chat message and verify only the selected text is copied.
  6. Right click a message without selecting any text > Copy to clipboard, and verify the full message is still copied.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests (copy to clipboard is a client-side operation).

QA Steps

// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".

  1. Go to a workspace chat and create an expense.
  2. Submit, approve, and mark the expense as paid so a "marked as paid" system message appears.
  3. Select just the word "marked" in that system message, right click > Copy to clipboard.
  4. Paste into the composer and verify only "marked" is pasted (not the full "marked as paid" message).
  5. Right click a message without selecting any text > Copy to clipboard, and verify the full message is still copied.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Co-authored-by: Sahil <thesahindia@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team July 7, 2026 16:07
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I created this PR from an upstream branch since I don't have push access to your fork.

To take ownership of this branch and be able to push updates, run:

git remote add upstream https://github.com/Expensify/App.git
git fetch upstream claude-copySelectionForSystemMessages
git checkout -b claude-copySelectionForSystemMessages upstream/claude-copySelectionForSystemMessages
git push -u origin claude-copySelectionForSystemMessages

Then you can close this PR and open a new one from your fork.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 I checked the failing checks — the only one failing is PR Author Checklist / checklist, and it's failing for a non-code reason:

PR Author Checklist is not completely filled out. Please check every box to verify you've thought about the item.

All other checks are passing or still running (run). There's no code fix to push here — this check just needs the boxes in the PR Author Checklist section (and the Tests / QA Steps) filled out by the human co-author. I don't tick those on a person's behalf, so this one is on you, thesahindia.

Once the checkboxes are completed the check will re-run and pass. If a different check fails after the pending ones finish, re-tag me and I'll dig into that.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
...es/inbox/report/ContextMenu/ContextMenuActions.tsx 21.84% <44.44%> (-22.41%) ⬇️
... and 104 files with indirect coverage changes

@thesahindia

Copy link
Copy Markdown
Member

@MelvinBot, mark off all the items in the author checklist

@MelvinBot

Copy link
Copy Markdown
Contributor Author

✅ Done — I checked off all items in the PR Author Checklist section.

Note: I left the two "Verify that no errors appear in the JS console" boxes under the Tests and QA Steps sections unchecked, since those aren't part of the author checklist. Let me know if you'd like those marked too.

@thesahindia

Copy link
Copy Markdown
Member

Let me know if you'd like those marked too.

Yes do it @MelvinBot. And mark the PR as ready for review

@MelvinBot MelvinBot marked this pull request as ready for review July 8, 2026 05:45
@MelvinBot MelvinBot requested a review from a team as a code owner July 8, 2026 05:45
@melvin-bot melvin-bot Bot requested review from thesahindia and removed request for a team July 8, 2026 05:45
@melvin-bot

melvin-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

@thesahindia Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot requested review from trjExpensify and removed request for a team July 8, 2026 05:45
@MelvinBot

Copy link
Copy Markdown
Contributor Author

✅ Done:

  • Checked both "Verify that no errors appear in the JS console" boxes (under Tests and QA Steps).
  • Marked the PR as ready for review (it's no longer a draft).

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ CONSISTENCY-3 (docs)

This new if (selection) branch copies the mention-cleanup logic verbatim from the existing else if (content) fallback branch further down in the same handler (the identical setClipboardMessage(<value>.replaceAll(/(<mention-user>)(.*?)(<\/mention-user>)/gi, (match, openTag, innerContent, closeTag) => { const modifiedContent = Str.removeSMSDomain(innerContent) || ''; return openTag + modifiedContent + closeTag || ''; })) block). The only difference is selection vs content. Duplicating this regex/replace logic means a future fix to the mention handling has to be made in two places and risks the branches drifting apart.

Extract the shared logic into a small helper and call it from both branches, e.g.:

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 || '';
        }),
    );
}

Then use setClipboardMessageWithCleanedMentions(selection) in the new branch and setClipboardMessageWithCleanedMentions(content) in the existing else if (content) branch.


Reviewed at: fcc8e2a | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@MelvinBot, implement this

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.

Done ✅ Extracted the shared mention-cleanup logic into a helper, setClipboardMessageWithCleanedMentions, and called it from both the new if (selection) branch and the existing else if (content) fallback, removing the duplicated regex/replace.

Pushed as 3b23fb3.

Checks run locally
  • npm run fmt (oxfmt) — clean
  • npm run lint-changed — passed
  • npm run typecheck-tsgo — passed
  • npm run react-compiler-compliance-check check — passed (no components/hooks in this file)
  • npm test -- tests/unit/ContextMenuActionsCopyMessageTest.ts — 2 passed

@MelvinBot

Copy link
Copy Markdown
Contributor Author

The only failing check is PR Reviewer Checklist / checklist, and it's not a code failure — nothing I can push will fix it.

It fails with No PR Reviewer Checklist was found. That job scans the PR comments for a completed reviewer checklist and errors out because one hasn't been posted yet. Every real CI check (Bun/Jest tests, typecheck, ESLint, Oxfmt, build, perf, Storybook, etc.) is passing.

To clear it: the assigned reviewer needs to complete and post the PR Reviewer Checklist on this PR; the check will re-run and pass. No branch change is required.

Co-authored-by: Sahil <thesahindia@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner July 8, 2026 06:03
@melvin-bot melvin-bot Bot requested review from flodnv and removed request for a team July 8, 2026 06:03
@melvin-bot

melvin-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

@flodnv Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@thesahindia

thesahindia commented Jul 8, 2026

Copy link
Copy Markdown
Member

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Screen.Recording.2026-07-08.at.1.01.43.PM.mov
Android: mWeb Chrome
Screen.Recording.2026-07-08.at.12.31.48.PM.mov
iOS: HybridApp
iOS: mWeb Safari
Screen.Recording.2026-07-08.at.4.05.10.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-07-08.at.10.55.30.AM.mov

@flodnv

flodnv commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@thesahindia lmk when you're done on your end, and I can merge this

@thesahindia

Copy link
Copy Markdown
Member

The fix can't be tested on Safari Desktop because the selection is cleared when the context menu opens.

Screen.Recording.2026-07-08.at.11.02.05.AM.mov

@thesahindia thesahindia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Works well!

@thesahindia

Copy link
Copy Markdown
Member

@thesahindia lmk when you're done on your end, and I can merge this

@flodnv, we can merge this.

@flodnv flodnv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All good with this @trjExpensify ?

@trjExpensify trjExpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is fine, as it's consistent with highlighting normal text and using the copy button in the context menu. 👍

@flodnv flodnv merged commit f65848c into main Jul 8, 2026
44 of 45 checks passed
@flodnv flodnv deleted the claude-copySelectionForSystemMessages branch July 8, 2026 10:54
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🚧 flodnv has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

OSBotify commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

OSBotify commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/flodnv in version: 9.4.32-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor Author

No help site changes required

I reviewed the changes in this PR against the help site articles under App/docs/articles.

This PR is a narrow bug fix to copy-to-clipboard behavior: when a user highlights part of a system message (e.g. "marked as paid", approved, reimbursed) and copies via the context menu, it now copies only the highlighted selection instead of the full reconstructed message — matching how regular chat messages already behaved.

Why no docs update is needed:

  • The help site does not document copy-to-clipboard or partial-text-selection behavior anywhere. The only article touching the message context menu (Chat-Features-and-Moderation-Tools.md) covers Edit comment, Delete comment, and Reply in thread — not copying.
  • No user-facing feature name, tab, setting label, or button changed. This is an internal behavior correction that makes system messages behave consistently with regular messages.

Since there is no documented behavior that this change contradicts or adds to, no draft help site PR was created.

@thesahindia, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/grgia in version: 9.4.32-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants