Skip to content

Commit c0bb3e9

Browse files
committed
Fix step counting bug in MutationObserver
1 parent 8d588ad commit c0bb3e9

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

js/linenumbering.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,30 @@ class LineNumberer {
8282
console.warn(e);
8383
}
8484
}
85-
// NOTE: This block might not actually be required...
86-
// const paragraphs = Array.from(addedNode.querySelectorAll('.kix-paragraphrenderer'));
87-
// for (const paragraph of paragraphs) {
88-
// const pageContent = addedNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
89-
// if (pageContent.parentNode.classList.contains('kix-page-content-wrapper')) {
90-
// const paragraphs = pageContent.querySelectorAll('.kix-paragraphrenderer');
91-
// paragraphs[0].classList.add('ln-document-right-border');
92-
// paragraphs[paragraphs.length - 1].classList.add('ln-document-right-border');
93-
// }
94-
// }
9585
}
9686
}
9787

98-
const lines = Array.from(document.getElementsByClassName('numbered'));
99-
for (let i = 0, ln = this.settings.start; i < lines.length; i++, ln++) {
100-
const line = lines[i];
101-
if (ln % this.settings.step == 0) {
102-
line.classList.add('visible');
103-
} else {
104-
line.classList.remove('visible');
88+
const lineBlocks = []
89+
if (this.settings.type == numbering.EACH_PAGE) {
90+
const pages = Array.from(document.body.querySelectorAll(".kix-page"));
91+
for (const page of pages) {
92+
lineBlocks.push(Array.from(page.querySelectorAll(".numbered")));
10593
}
94+
} else {
95+
lineBlocks.push(Array.from(document.getElementsByClassName('numbered')))
10696
}
10797

98+
for (const lines of lineBlocks) {
99+
for (let i = 0, ln = this.settings.start; i < lines.length; i++, ln++) {
100+
const line = lines[i];
101+
if (ln % this.settings.step == 0) {
102+
line.classList.add('visible');
103+
} else {
104+
line.classList.remove('visible');
105+
}
106+
}
107+
}
108+
108109
return;
109110
});
110111
}
@@ -151,11 +152,11 @@ class LineNumberer {
151152
* @return list of list of line objects
152153
*/
153154

154-
if (this.resetCountOnNewPage) {
155+
if (this.settings.type == numbering.EACH_PAGE) {
155156
const lineBlocks = []
156157

157-
const pages = document.body.querySelectorAll(".kix-page");
158-
for (const page in pages) {
158+
const pages = Array.from(document.body.querySelectorAll(".kix-page"));
159+
for (const page of pages) {
159160
lineBlocks.push(Array.from(page.querySelectorAll(".kix-lineview")));
160161
}
161162

@@ -297,7 +298,7 @@ class LineNumberer {
297298

298299
for (const lines of this.lineBlocks) {
299300
const consideredLines = lines.filter(line => this.shouldCountLine(line));
300-
this.numberLinesSequentially(consideredLines, 1, this.settingsManager.settings.step);
301+
this.numberLinesSequentially(consideredLines, this.settingsManager.settings.start, this.settingsManager.settings.step);
301302
}
302303
}
303304

0 commit comments

Comments
 (0)