Add lightweight Copy action for issue/PR description and comments #2971
Zak Siddiqui opened 2 days ago

Summary

Add a Copy control next to Quote (or equivalent) that copies the full issue/PR description or comment Markdown to the clipboard.

Motivation

Users sometimes want to share a description or comment while preserving Markdown. Today they must use Quote (into a reply editor) or Edit (when permitted) to reach the raw Markdown. A dedicated Copy action would make that one click.

Scope

  • Full description / full comment body only
  • Copy the already-loaded Markdown source (same data Quote uses)
  • Reuse the existing CopyToClipboardLink pattern
  • Place the control beside Quote on comments, and in a comparable place for the description

Out of scope

  • Selection-aware “copy Markdown behind highlighted rendered text”
  • Any server-side reverse conversion from rendered HTML to Markdown
  • New client libraries or significant client footprint growth

Constraints

Keep server compute and client code weight minimal: no extra request on click beyond reading Markdown already present for the page; no new feature stack.

Related discussion: issue #2970

  • Zak Siddiqui commented 2 days ago

    @servicedesk please create an implementation plan based on the above, including suggested code changes

  • Service Desk commented 2 days ago

    @zaakiy Implementation plan for the lightweight Copy action:

    Approach

    Add a full-body Copy control in the shared comment viewer (CommentPanel), next to Quote. Issue/PR descriptions and comments all render through that panel, so one change covers the stated scope without touching each caller separately.

    Existing callers that get Copy automatically:

    • Issue description — IssuePrimaryPanel
    • Issue comments — IssueCommentPanel
    • PR description — PullRequestDetailPage
    • PR comments — PullRequestCommentPanel

    This reuses CopyToClipboardLink / ClipboardJS (same pattern as AI chat “Copy as Markdown”). Markdown is already available when the viewer is built (getComment(), same source Quote uses), so click does not need a new server round-trip or HTML→Markdown conversion.

    Suggested code changes

    1. CommentPanel.html (viewFrag action row)
      Insert a Copy control beside Quote, matching the existing text-link style (Edit / Quote / Delete), e.g. after Quote and before Delete:

      <wicket:enclosure child="copy">
        <span class="d-first-child-none dot mr-2"></span>
        <a wicket:id="copy" class="text-muted text-hover-primary mr-2"><wicket:t>Copy</wicket:t></a>
      </wicket:enclosure>
      

      Text label (not icon-only) keeps the row consistent; tippy can still show copy/copied feedback.

    2. CommentPanel.java (newViewer())
      Add a CopyToClipboardLink with an IModel that returns getComment(), e.g. tooltip _T("Copy Markdown") / default “Copied to clipboard”.
      Visibility: show when content is non-blank (StringUtils.isNotBlank(getComment())). Unlike Quote, do not require a signed-in user — copy only needs view access.
      Optional: isCopyEnabled() defaulting to true if a caller ever needs to hide it (mirrors isQuoteEnabled()).

    3. No new JS / libraries
      copy-to-clipboard.js already supports links without an SVG (icon swap is skipped; tippy still updates). Do not add selection mapping or reverse Markdown conversion.

    4. Translations
      Use <wicket:t>Copy</wicket:t> and _T(...) for the tooltip. Do not hand-edit generated Translation_*.java files.

    5. Out of scope for this change

      • Code review comments (CodeCommentPanel has its own Quote row; can be a follow-up if desired)
      • Selection-aware copy
      • Any extra Ajax on click

    Why this stays lightweight

    • Server: no new endpoint or compute on click; text is taken from the already-loaded entity field at render.
    • Client: one extra anchor + existing ClipboardJS helper; no new dependency.
    • Scope: full body only, same data Quote already uses.

    Manual test plan

    • Issue with description: Copy puts full Markdown on clipboard; empty description hides Copy.
    • Issue comment: same; works when logged out if the comment is visible.
    • PR description and PR comment: same.
    • After Edit/Save, Copy reflects the updated Markdown.
    • Quote / Edit / Delete behavior unchanged.

    Does this plan look good to proceed?

  • Zak Siddiqui commented 2 days ago

    LGTM

  • Service Desk commented 2 days ago

    @zaakiy Thanks for the LGTM. I do not have permission to write code in this project (tod issue checkout --for-write returned HTTP 403), so I cannot implement the Copy action myself. @robin please take over implementation based on the approved plan.

  • Robin Shen changed fields 16 hours ago
    Name Previous Value Current Value
    Assignee
    robin
    wh
  • Work Horse referenced from pull request 16 hours ago
  • Work Horse commented 16 hours ago

    Implemented the approved plan: added a Copy control next to Quote in CommentPanel, reusing CopyToClipboardLink with the already-loaded Markdown. It covers issue/PR descriptions and comments, is shown when content is non-blank (no login required), and can be hidden via isCopyEnabled().

    See also pr #110

1/1
Type
Improvement
Priority
Minor
Assignee
Labels
No labels
Issue Votes (0)
Watchers (4)
Reference
OD-2971
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover