(element: HTMLElement)
| 51 | |
| 52 | // https://github.com/refined-github/refined-github/issues/6336#issuecomment-1498645639 |
| 53 | export function repositionAnchors(element: HTMLElement): void { |
| 54 | // TODO [2027-01-01]: bump min firefox version to 147 and safari to 26 |
| 55 | if (!CSS.supports('anchor-name: --test')) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | // Safety measure |
| 60 | // DOM changes made by this function is unnecessary if the textarea doesn't exist and can cause issues |
| 61 | if (!elementExists('#read-only-cursor-text-area')) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | const container = closestElement('.react-code-file-contents', element).parentElement!; |
| 66 | |
| 67 | const codeLine = closestElementOptional('[id]', element); |
| 68 | if (!codeLine) { |
| 69 | throw new Error('Could not find parent code line'); |
| 70 | } |
| 71 | |
| 72 | const links = $$('a', codeLine); |
| 73 | for (const [index, link] of links.entries()) { |
| 74 | const anchor = `--rgh-${codeLine.id}-${index}`; |
| 75 | link.replaceWith(<span style={{anchorName: anchor, opacity: 0}}>{link.textContent}</span>); |
| 76 | link.className = 'react-code-text rgh-anchored-link'; |
| 77 | link.style.positionAnchor = anchor; |
| 78 | container.prepend(link); |
| 79 | } |
| 80 | |
| 81 | // Hide overflow |
| 82 | container.style.position = 'relative'; |
| 83 | } |
| 84 | |
| 85 | export function linkifyIssues( |
| 86 | currentRepo: {owner?: string; name?: string}, |
no test coverage detected