ace2_inner: Operate on Elements, not Nodes

pull/5153/head
Richard Hansen 2021-08-14 23:03:33 -04:00
parent aad75e4661
commit a5f9c60a34
1 changed files with 7 additions and 9 deletions

View File

@ -3546,24 +3546,25 @@ function Ace2Inner(editorInfo, cssManagers) {
const innerdocbodyStyles = getComputedStyle(document.body); const innerdocbodyStyles = getComputedStyle(document.body);
const defaultLineHeight = parseInt(innerdocbodyStyles['line-height']); const defaultLineHeight = parseInt(innerdocbodyStyles['line-height']);
let docLine = document.body.firstChild; let docLine = document.body.firstElementChild;
let currentLine = 0; let currentLine = 0;
let h = null; let h = null;
// First loop to calculate the heights from doc body // First loop to calculate the heights from doc body
while (docLine) { while (docLine) {
if (docLine.nextSibling) { const nextDocLine = docLine.nextElementSibling;
if (nextDocLine) {
if (currentLine === 0) { if (currentLine === 0) {
// It's the first line. For line number alignment purposes, its // It's the first line. For line number alignment purposes, its
// height is taken to be the top offset of the next line. If we // height is taken to be the top offset of the next line. If we
// didn't do this special case, we would miss out on any top margin // didn't do this special case, we would miss out on any top margin
// included on the first line. The default stylesheet doesn't add // included on the first line. The default stylesheet doesn't add
// extra margins/padding, but plugins might. // extra margins/padding, but plugins might.
h = docLine.nextSibling.offsetTop - parseInt( h = nextDocLine.offsetTop - parseInt(
window.getComputedStyle(document.body) window.getComputedStyle(document.body)
.getPropertyValue('padding-top').split('px')[0]); .getPropertyValue('padding-top').split('px')[0]);
} else { } else {
h = docLine.nextSibling.offsetTop - docLine.offsetTop; h = nextDocLine.offsetTop - docLine.offsetTop;
} }
} else { } else {
// last line // last line
@ -3584,7 +3585,7 @@ function Ace2Inner(editorInfo, cssManagers) {
} else { } else {
lineHeights.push(defaultLineHeight); lineHeights.push(defaultLineHeight);
} }
docLine = docLine.nextSibling; docLine = nextDocLine;
currentLine++; currentLine++;
} }
@ -3593,10 +3594,7 @@ function Ace2Inner(editorInfo, cssManagers) {
if (newNumLines !== sideDivInner.children.length) { if (newNumLines !== sideDivInner.children.length) {
while (sideDivInner.children.length < newNumLines) appendNewSideDivLine(); while (sideDivInner.children.length < newNumLines) appendNewSideDivLine();
// Remove extra lines while (sideDivInner.children.length > newNumLines) sideDivInner.lastElementChild.remove();
while (sideDivInner.children.length > newNumLines) {
sideDivInner.removeChild(sideDivInner.lastChild);
}
} }
for (const [i, sideDivLine] of Array.prototype.entries.call(sideDivInner.children)) { for (const [i, sideDivLine] of Array.prototype.entries.call(sideDivInner.children)) {