Add “Copy Source” to markup comment menu#36726
Conversation
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.
wxiaoguang
left a comment
There was a problem hiding this comment.
It just make the page much longer than before (larger response size).
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
|
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. |
|
Fixed with f4c78cd, this was a pre-existing issue that also affected "Copy Link" in the same menu. |
Signed-off-by: silverwind <me@silverwind.io>
|
Tooltip is still not quite bug-free, I'm checking. |
|
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.
|
Signed-off-by: silverwind <me@silverwind.io>
Signed-off-by: silverwind <me@silverwind.io>
There was a problem hiding this comment.
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 theHashTag()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.
Signed-off-by: silverwind <me@silverwind.io>
|
What I did not test here yet is whether it also works correctly on inline comments. Redacting my review until then. |
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>
Tested, works fine on inline review comments. |
* 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) ...

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:
After:
Testing
···context menu on any comment (including comments you cannot edit)Closes #36722.