Skip to content

Add “Copy Source” to markup comment menu#36726

Merged
wxiaoguang merged 19 commits intogo-gitea:mainfrom
shafi-VM:add-copy-source-button
Mar 1, 2026
Merged

Add “Copy Source” to markup comment menu#36726
wxiaoguang merged 19 commits intogo-gitea:mainfrom
shafi-VM:add-copy-source-button

Conversation

@shafi-VM
Copy link
Copy Markdown
Contributor

Description

Any user with read access to a comment can now copy its raw markdown source via the ··· context menu — no edit permission required.

Previously, copying the markdown source of a comment (e.g. to reuse a table, formatting, or template) required edit access. This change adds a Copy Source menu item for all readers, alongside the existing Copy Link option.

This improves usability for users who want to reference or reuse formatted content without needing permission to modify the comment.

Screenshots

Before:

Menu without Copy Source
(Copy Link, Quote Reply, Reference in New Issue, Edit, Delete)

After:

Menu with Copy Source
(Copy Link, Copy Source, Quote Reply, Reference in New Issue, Edit, Delete)

Testing

  1. Open any issue or pull request with a comment
  2. Click the ··· context menu on any comment (including comments you cannot edit)
  3. Click Copy Source
  4. Paste into a text editor — the raw markdown source should appear

Closes #36722.

Add a new localization key (repo.issues.context.copy_source) to en-US locale and insert a context menu item in the issue comment view template. The new menu entry exposes the comment's raw content via data-clipboard-text, allowing users to copy the source of an issue comment from the context menu.
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 23, 2026
@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Feb 23, 2026
Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

It just make the page much longer than before (larger response size).

You shouldn't duplicate the issue content again and again.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 23, 2026
@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 23, 2026

You shouldn't duplicate the issue content again and again.

Where else do we have the source already?

One thing to consider is that the source would be incorrect after an edit, so the feature will involve some JS too.

Instead of duplicating the comment content in a data attribute, read the raw markup from the already-present hidden raw-content div, consistent with how Quote Reply accesses the same data
@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Feb 23, 2026
@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 24, 2026

It works but there is a issue with the temporary tooltip "Copied!" not hiding, investigating. I think maybe we should just not show that tooltip on dropdowns.

@silverwind
Copy link
Copy Markdown
Member

Fixed with f4c78cd, this was a pre-existing issue that also affected "Copy Link" in the same menu.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 24, 2026
Signed-off-by: silverwind <me@silverwind.io>
silverwind and others added 2 commits February 24, 2026 06:00
Signed-off-by: silverwind <me@silverwind.io>
@silverwind
Copy link
Copy Markdown
Member

Tooltip is still not quite bug-free, I'm checking.

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 24, 2026

Ok all fixed. The problem was with empty content. The menu item is now disabled when it would copy nothing. With 608e091, disabled state is now also correctly set after edit.

image

Signed-off-by: silverwind <me@silverwind.io>
Signed-off-by: silverwind <me@silverwind.io>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a "Copy Source" button to the comment context menu that allows any user with read access to copy the raw markdown source of comments without needing edit permissions. Previously, users could only view and copy markdown source when editing a comment, which required edit access.

Changes:

  • Added "Copy Source" menu item to all comment context menus, positioned between "Copy Link" and "Quote Reply"
  • Extended clipboard handler to support copying from DIV elements using textContent (previously only INPUT/TEXTAREA)
  • Added tooltip auto-hide timeout for dropdown menus to fix tooltip persistence issue
  • Changed raw content DIV IDs from hardcoded issuecomment-{ID} pattern to use the HashTag() method for consistency

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
templates/repo/issue/view_content/context_menu.tmpl Added "Copy Source" menu item with disabled state for empty comments
templates/repo/issue/view_content.tmpl Updated raw content DIV ID to use HashTag for issues
templates/repo/issue/view_content/comments.tmpl Updated raw content DIV IDs to use HashTag for comments (2 locations)
templates/repo/issue/view_content/conversation.tmpl Updated raw content DIV ID to use HashTag for code review comments
templates/repo/diff/comments.tmpl Updated raw content DIV ID to use HashTag for diff comments
web_src/js/features/clipboard.ts Extended to support DIV elements and disabled state checking
web_src/js/features/repo-issue-edit.ts Added logic to update "Copy Source" disabled state after editing
web_src/js/modules/tippy.ts Added timeout to auto-hide tooltips in dropdown menus
options/locale/locale_en-US.json Added English translation string for "Copy Source"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@silverwind silverwind added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Feb 24, 2026
Signed-off-by: silverwind <me@silverwind.io>
@silverwind silverwind changed the title Add “Copy Source” to comment menu for all users Add “Copy Source” to markup comment menu Feb 24, 2026
@silverwind
Copy link
Copy Markdown
Member

What I did not test here yet is whether it also works correctly on inline comments. Redacting my review until then.

@silverwind silverwind self-requested a review February 24, 2026 11:28
@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 24, 2026
silverwind and others added 2 commits February 28, 2026 16:13
The "Copy Source" button no longer needs to be disabled when there is
no content, simplifying the clipboard and context menu logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 28, 2026
@silverwind
Copy link
Copy Markdown
Member

What I did not test here yet is whether it also works correctly on inline comments. Redacting my review until then.

Tested, works fine on inline review comments.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 1, 2026
@wxiaoguang wxiaoguang enabled auto-merge (squash) March 1, 2026 08:39
@wxiaoguang wxiaoguang merged commit e3cf360 into go-gitea:main Mar 1, 2026
26 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Mar 1, 2026
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 2, 2026
* giteaofficial/main: (21 commits)
  Enable docker layer caching for `dry-run` and `nightly` container builds (go-gitea#36738)
  Add admin badge to navbar avatar (go-gitea#36790)
  WorkflowDispatch api optionally return runid (go-gitea#36706)
  upgrade minimatch (go-gitea#36760)
  Add `never` option to `PUBLIC_URL_DETECTION` configuration (go-gitea#36785)
  Refactor avatar package, support default avatar fallback (go-gitea#36788)
  Mark unused&immature activitypub as "not implemented" (go-gitea#36789)
  Add “Copy Source” to markup comment menu (go-gitea#36726)
  Update Nix flake (go-gitea#36787)
  Implements OIDC RP-Initiated Logout (go-gitea#36724)
  Fix README symlink resolution in subdirectories like .github (go-gitea#36775)
  [skip ci] Updated translations via Crowdin
  Correct spelling (go-gitea#36783)
  refactor: replace legacy tw-flex utility classes with flex-text-block/inline (go-gitea#36778)
  Fix `no-content` message not rendering after comment edit (go-gitea#36733)
  Fix typos and grammar in English locale (go-gitea#36751)
  Move Fomantic dropdown CSS to custom module (go-gitea#36530)
  Use "Enable Gravatar" but not "Disable" (go-gitea#36771)
  feat: add branch_count to repository API (go-gitea#35351) (go-gitea#36743)
  Deprecate RenderWithErr (go-gitea#36769)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend modifies/templates This PR modifies the template files type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Copy Source" button for markup comments

5 participants