MCPcopy Index your code
hub / github.com/refined-github/refined-github / repositionAnchors

Function repositionAnchors

source/github-helpers/dom-formatters.tsx:53–83  ·  view source on GitHub ↗
(element: HTMLElement)

Source from the content-addressed store, hash-verified

51
52// https://github.com/refined-github/refined-github/issues/6336#issuecomment-1498645639
53export 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
85export function linkifyIssues(
86 currentRepo: {owner?: string; name?: string},

Callers 2

linkifyIssuesFunction · 0.85
linkifyUrlsFunction · 0.85

Calls 1

prependMethod · 0.80

Tested by

no test coverage detected