Skip to content

linkify-code broken on new file viewer #6336

Description

@fregante

Description

Screenshot
Screenshot

How to replicate the issue + URL

It's not enabled on
https://github.com/refined-github/refined-github/blob/be756e68dd4bf24d53e802e1fec126506979fa80/test/linkify-urls-in-code.js

But you can see it working in this live code embed:

test('isIssue', batchTestText, linkifyURLsInCode.hasIssue, [
'#1',
'#12',
'an issue in the middle #123 of some text' // Only link to issues in comments, see #381
], [
'#a',
'1234'
]);
test('findURLs', batchTestArray, linkifyURLsInCode.findURLs, [
'http://github.com/',
'https://www.github.com',
'https://github.com/orgs/test/dashboard',
'a long string of text with a url at the end: https://github.com/dashboard?param=test'
], [
'https://github',
'github',
'github.com',
'github/whatever/text'
]);

Extension version

23.2.1

Browser(s) used

Safari

Activity

  1. changed the title [-]`linkify-code` broken[/-] [+]`linkify-code` broken on new file viewer[/+] on Feb 11, 2023
  2. added
    Please! ♥︎
    on Feb 11, 2023
  3. amanmalh commented on Feb 12, 2023

    @amanmalh
    Contributor

    Hi @fregante, I need more clarification on this. I tested this on chrome, as well as safari. The URLs under 'findURLs' test seem to be working fine for me. The issue reference in the comment is working fine as well. What exactly is broken?

  4. fregante commented on Feb 12, 2023

    @fregante
    MemberAuthor
  5. amanmalh commented on Feb 13, 2023

    @amanmalh
  6. StefanLobbenmeierObjego commented on Mar 3, 2023

    @StefanLobbenmeierObjego
  7. fregante commented on Mar 3, 2023

    @fregante
    Author
  8. kidonng commented on Apr 6, 2023

    @kidonng
    Member

    This seems tricky because there's a <textarea> overlay above the actual code. We can linkify the code but no one is able to click them 😅

    Or alternatively, we catch the click events and re-dispatch them ourselves 🤔

  9. fregante commented on Apr 6, 2023

    @fregante
    MemberAuthor

    🤔 what's that textarea for? Is the code inside it? How is the user able to select it?

  10. kidonng commented on Apr 6, 2023

    @kidonng
    Member

    Presumably for getting cursor position and acting on it, as it is easier than dealing with text nodes.

    The real bummer is that the highlighted code is now pseudo-elements:

    .react-file-line [data-code-text]::before {
        content: attr(data-code-text);
    }

    Which means in addition to dealing with clicks, we need to construct the DOM back ourselves. And a11y will suffer.

    I can't think of an efficient way to do all these without breaking GitHub functionality.

  11. fregante commented on Apr 6, 2023

    @fregante
    Author
  12. kidonng commented on Apr 6, 2023

    @kidonng
  13. fregante commented on Apr 6, 2023

    @fregante
    Author
  14. 6 remaining items

  15. 134130 commented on Aug 18, 2023

    @134130
    Contributor

    🤔 We can implement in two ways.

    • Just re-using GitHub's highlighting elements.
      • Simple and light way. Not harming GitHub's text editor
    • Overlaying with display: absolute | related
      • Looks more pretty since we can use anchor tag with hovering css.

    And this is my rough implement with first way.
    화면 기록 2023-08-18 23 46 41

  16. fregante commented on Aug 18, 2023

    @fregante
    MemberAuthor

    How does the first way work? Can you send a minimal PR? Or demo code?

    Edit: I think you're suggesting the demo GIF I used earlier. The problem is that that could only highlight the entire string instead of just the URL. This would not work if a comment has a link and especially if it has more than one link.

    The second suggestion would work if we add a single clickable icon somewhere nearby, but we cannot highlight the exact text or potentially even the exact line (if a comment wraps)

  17. 134130 commented on Aug 19, 2023

    @134130
    Contributor

    Exactly.

  18. self-assigned this
    on Aug 10, 2024
  19. changed the title [-]All linkifier features broken on new file viewer[/-] [+]⚠️ All linkifier features broken on new file viewer[/+] on Dec 8, 2024
  20. locked and limited conversation to collaborators on Dec 8, 2024
  21. unlocked this conversation on Dec 8, 2024
  22. SunsetTechuila commented on Jan 16, 2026

    @SunsetTechuila
    Contributor

    I think CSS anchoring (2024) will be another way to overlay content without altering the DOM

    Here is a demo of the only solution I see (go to https://github.com/refined-github/refined-github/blob/be756e68dd4bf24d53e802e1fec126506979fa80/test/linkify-urls-in-code.js and run this in the devtools console):

    const targetLine = document.querySelector('#LC42');
    const link = document.createElement("a");
    link.classList.add("rgh-linkified-code");
    link.href = "https://github.com";
    link.rel = "noreferrer noopener";
    targetLine.children[0].replaceWith(link);
    link.append("'https://github.com'");
    
    const link2 = link.cloneNode();
    link.style.anchorName = "--line";
    link2.style.positionAnchor = "--line";
    link2.style.position = "fixed";
    link2.style.top = "anchor(top)";
    link2.style.left = "anchor(left)";
    link2.style.zIndex = "2";
    link2.style.opacity = "0";
    document.querySelector("#read-only-cursor-text-area").before(link2);
    link2.append("'https://github.com'");

    but it's not here yet

    It is now 🎉 (almost):

    https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/position-anchor#browser_compatibility

  23. changed the title [-]⚠️ All linkifier features broken on new file viewer[/-] [+]`linkify-code` broken on new file viewer[/+] on Jul 31, 2026
  24. fregante commented on Jul 31, 2026

    @fregante
    MemberAuthor

    Reopening because the fix was removed. Now the feature works on comments like before.

    The solution is most likely still the same, except that the CSS anchors need to target a different element.

  25. removed their assignment
    on Aug 2, 2026
  26. kidonng commented on Aug 27, 2026

    @kidonng
    Member

    Not sure if this is already known, I only found out how the "wrap lines" option makes a difference just now.

    Wrap lines enabled:

    • Lines are virtualized (find in page is hijacked)
    • There is no #read-only-cursor-text-area blocking clicks
    • linkify-code works

    Wrap lines disabled:

    • Lines are not virtualized (find in page is native)
    • #read-only-cursor-text-area blocking clicks
    • linkify-code works, but you can not click the links
    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Please! ♥︎acceptedbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions