Skip to content

Commit a86f0f9

Browse files
committed
fix(webview): outdated comment
1 parent 27431c1 commit a86f0f9

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(function(){
22
const containers = document.querySelectorAll('.outdated-comment, .outdated-diff-comment-container');
33
for (const container of Array.from(containers)) {
4-
container.classList.add('open');
4+
container.setAttribute('open', true);
5+
container.classList.add('open'); // for old style(GHE ~2018.08)
56
}
67
})();

‎src/Electron/Component/WebViewComponentInjection/highlight-comment.js‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(){
1+
(async function(){
22
const prevReadAt = _prevReadAt_;
33

44
function highlightComment(comment, prevReadAt) {
@@ -12,6 +12,33 @@
1212
}
1313
}
1414

15+
function sleep(msec) {
16+
return new Promise((resolve) => {
17+
setTimeout(resolve, msec);
18+
});
19+
}
20+
21+
// outdatedが非同期になってしまったので、一度openして中を読み込ませてから、処理を行う
22+
// todo: GHEの場合、リクエストが増えるのが心配
23+
{
24+
const containers = document.querySelectorAll('.outdated-comment, .discussion-item');
25+
26+
if (containers.length) {
27+
// outdatedしている箇所を一度openして、中身を読み込ませる
28+
for (const container of Array.from(containers)) {
29+
container.setAttribute('open', true);
30+
container.removeAttribute('open');
31+
}
32+
33+
// 最後のoutdatedの中が読み込まれるまで待機
34+
const lastContainer = containers[containers.length - 1];
35+
for (let i = 0; i < 10; i++) {
36+
await sleep(100);
37+
if (lastContainer.querySelector('.review-comment')) break;
38+
}
39+
}
40+
}
41+
1542
{
1643
const comments = document.querySelectorAll('.review-comment');
1744
for (const comment of Array.from(comments)) {
@@ -37,7 +64,10 @@
3764
const containers = document.querySelectorAll('.outdated-comment, .discussion-item');
3865
for (const container of Array.from(containers)) {
3966
const comment = container.querySelector('.highlight-comment');
40-
if (comment) container.classList.add('open');
67+
if (comment) {
68+
container.setAttribute('open', true);
69+
container.classList.add('open'); // for old style(GHE ~2018.08)
70+
}
4171
}
4272
}
4373
})();

0 commit comments

Comments
 (0)