Skip to content

Commit 9ed3ebc

Browse files
leomotystefanbuck
authored andcommitted
Rerun Octo-Linker when blobs are expanded (OctoLinker#505)
<!-- Thanks for filing a pull request! Please look at the following checklist to ensure that your PR can be accepted quickly: --> This is a possible implementation for OctoLinker#453, we observe the DOM, if any new `.blob-expanded` nodes are added, then the extension is rerun. As far as testing goes, I will wait for feedback, I added a single test that clickes the specific `.js-expand` element and then tries to process a single line from it. ### Checklist: - [ ] If this PR is a new feature, please provide at least one example link - [x] Make sure all of the significant new logic is covered by tests
1 parent 38dd5c8 commit 9ed3ebc

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

e2e/automated.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,19 @@ describe('End to End tests', () => {
6969
});
7070
});
7171
});
72+
73+
describe('expanded blob', () => {
74+
it('should resolve after appending new blobs', async () => {
75+
const url =
76+
'https://github.com/OctoLinker/OctoLinker/pull/451/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2';
77+
const selector = '[data-line-number="45"] + td .octolinker-link';
78+
const expandSelector = '[data-right-range="44-55"]';
79+
80+
await page.goto(url);
81+
82+
await page.click(expandSelector);
83+
84+
await page.waitForSelector(selector);
85+
});
86+
});
7287
});

packages/core/octo-linker.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,23 @@ async function run(self) {
6565
clickHandler(matches);
6666
}
6767

68+
function observeExpand(self) {
69+
const observer = new MutationObserver(() => {
70+
run(self);
71+
});
72+
73+
for (const el of document.querySelectorAll('.diff-table tbody')) {
74+
observer.observe(el, { childList: true });
75+
}
76+
}
77+
6878
export default class OctoLinkerCore {
6979
constructor(options) {
7080
initialize(this, options);
7181
}
7282

7383
init() {
7484
injection(run.bind(null, this));
85+
observeExpand(this);
7586
}
7687
}

0 commit comments

Comments
 (0)