Skip to content

Commit 039da5c

Browse files
committed
GitHub: Make add line comment fix more robust when the code hasn't finished rendering.
It seems the comment buttons sometimes render before the code. So, we now match for both the comment button and the code and handle both in the same way.
1 parent a717205 commit 039da5c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

GitHubA11yFixes.user.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,15 @@ const DYNAMIC_TWEAK_ATTRIBS = [];
127127
// Tweaks that must be applied whenever a node is added/changed.
128128
const DYNAMIC_TWEAKS = [
129129
// Lines of code which can be commented on.
130-
{selector: '.add-line-comment',
130+
{selector: '.add-line-comment, span.blob-code-inner',
131131
tweak: el => {
132132
// Put the comment button after the code instead of before.
133-
// el is the Add line comment button.
134-
// nextElementSibling is the actual code.
135-
makeElementOwn(el.parentNode, [el.nextElementSibling, el]);
133+
let cell = el.parentNode;
134+
let code = cell.querySelector('.blob-code-inner');
135+
let comment = cell.querySelector('.add-line-comment');
136+
if (code && comment) {
137+
makeElementOwn(cell, [code, comment]);
138+
}
136139
}},
137140
// Make non-comment events into headings; e.g. closing/referencing an issue,
138141
// approving/requesting changes to a PR, merging a PR. Exclude commits and

0 commit comments

Comments
 (0)