Change the behaviour of clicking anchor links #2898
Zak Siddiqui opened 2 days ago

When an anchor link is clicked, such as for a comment, there is no need to navigate to it since it's already showing in the current view. Therefore, a better action would be to copy the link to the clipboard, instead of navigating to it which forces a scroll down to the anchor point and disturbs the UX of the user.

This enables the link to be immediately usable and pasteable elsewhere without requiring a right click and then copy.

  • Zak Siddiqui commented 2 days ago

    @servicedesk Can you analyse these requirements and provide some context or guidance?

    Don't assume. Ask high-level clarifying questions if needed.

    • Numbered questions (1, 2, 3, etc)
    • Lettered answer options (A, B, C, etc)
    • Pros and Cons? Your recommendation?
  • Service Desk commented 2 days ago

    @zaakiy Analysis and clarifying questions before we implement this:

    Current behaviour

    Comment/activity permalink icons (issue comments, PR comments, code-comment replies) use an in-page hash such as #IssueComment-<id>. Left-clicking updates the location hash and scrolls that element into view — even when the comment is already on screen. Absolute permalinks already exist server-side via UrlService (for example …/~issues/<n>#IssueComment-<id>, and similarly for PRs / code comments), and OneDev already has a reusable CopyToClipboardLink pattern with “copied” feedback.

    Recommendation

    Treat the chain/link icon next to comments as a copy-permalink control: on left-click, copy the absolute URL and do not scroll. Keep a real href (full permalink) so right-click / open-in-new-tab still work, and preventDefault only on a normal left-click. Start with comment/activity icons only — not every markdown heading anchor — unless you want broader scope.

    Questions

    1. Scope — which anchors should change?

      • A. Only comment/activity permalink icons (issue, PR, code-comment replies) — recommended
      • B. Also markdown heading anchors in rendered content
      • C. All in-page #… links product-wide
    2. What should be copied?

      • A. Absolute URL including server root (https://…/~issues/123#IssueComment-456) — recommended (pasteable elsewhere)
      • B. Site-relative path + hash (/project/~issues/123#…)
      • C. Hash only (#IssueComment-456)
    3. Address bar / scroll on left-click?

      • A. Copy only; no scroll and no hash change — recommended
      • B. Copy and update the URL hash, but suppress scroll
      • C. Copy and keep today’s navigate/scroll behaviour
    4. User feedback after copy?

      • A. Brief tippy/toast (“Link copied” / reuse existing copy-to-clipboard feedback) — recommended
      • B. No visible feedback
    5. Modifier / secondary actions?

      • A. Left-click copies; keep full permalink as href so middle-click / “Open in new tab” / “Copy link address” still work — recommended
      • B. Replace with a button that only copies (no navigable href)

    Please reply with your choices (e.g. 1A, 2A, 3A, 4A, 5A) or note any differences.

  • Zak Siddiqui commented 2 days ago
    1. A & B
    2. B - but ask @robin for confirmation
    3. A
    4. A
    5. A

    @servicedesk

  • Service Desk commented 2 days ago

    @zaakiy Recorded your choices:

    1. Scope: A & B — comment/activity permalink icons and markdown heading anchors
    2. Copy format: B (site-relative path + hash) — pending confirmation
    3. Left-click: A — copy only; no scroll and no hash change
    4. Feedback: A — brief tippy/toast
    5. Secondary actions: A — keep full permalink as href so middle-click / open-in-new-tab still work

    @robin For (2), zaakiy prefers a site-relative URL (e.g. /project/~issues/123#IssueComment-456) over an absolute URL including the server root. Relative stays portable if the site URL changes; absolute is more pasteable into email/chat outside the instance. Prefer B (site-relative) or A (absolute)?

  • Robin Shen commented 2 days ago

    Click the anchor link will update browser url to include the anchor, which is the standard behavior of clicking a link. Copying it to clipboard violates this convention.

  • Robin Shen changed state to 'Closed' 2 days ago
    Previous Value Current Value
    Open
    Closed
  • Zak Siddiqui commented 22 hours ago

    @robin in that case, I would kindly request a copy to clipboard button next to the anchor link. Which would copy the comment URL into the clipboard

  • Zak Siddiqui changed state to 'Open' 22 hours ago
    Previous Value Current Value
    Closed
    Open
1/1
Type
Improvement
Priority
Normal
Assignee
Labels
No labels
Issue Votes (0)
Watchers (3)
Reference
OD-2898
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover