From 1b890e3d4de9f18dcb3226d656fb68f0327d9b57 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 14 Aug 2021 20:47:10 -0400 Subject: [PATCH] ace2_inner: Replace `lineNumbersShown` with number of children --- src/static/js/ace2_inner.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index b0b0d3fb5..ffe0ffe61 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -73,7 +73,6 @@ function Ace2Inner(editorInfo, cssManagers) { lineSpan.appendChild(outerDoc.createTextNode('1')); lineDiv.appendChild(lineSpan); })(); - let lineNumbersShown = 1; const scroll = Scroll.init(outerWin); @@ -3594,7 +3593,7 @@ function Ace2Inner(editorInfo, cssManagers) { // Apply height to existing sidediv lines currentLine = 0; - while (sidebarLine && currentLine <= lineNumbersShown) { + while (sidebarLine && currentLine <= sideDivInner.children.length) { if (lineOffsets[currentLine] != null) { sidebarLine.style.height = `${lineOffsets[currentLine]}px`; sidebarLine.style.lineHeight = `${lineHeights[currentLine]}px`; @@ -3603,24 +3602,22 @@ function Ace2Inner(editorInfo, cssManagers) { currentLine++; } - if (newNumLines !== lineNumbersShown) { + if (newNumLines !== sideDivInner.children.length) { // Create missing line and apply height - while (lineNumbersShown < newNumLines) { - lineNumbersShown++; + while (sideDivInner.children.length < newNumLines) { const div = outerDoc.createElement('DIV'); + sideDivInner.appendChild(div); if (lineOffsets[currentLine]) { div.style.height = `${lineOffsets[currentLine]}px`; div.style.lineHeight = `${lineHeights[currentLine]}px`; } - $(div).append($(`${String(lineNumbersShown)}`)); - sideDivInner.appendChild(div); + $(div).append($(`${sideDivInner.children.length}`)); currentLine++; } // Remove extra lines - while (lineNumbersShown > newNumLines) { + while (sideDivInner.children.length > newNumLines) { sideDivInner.removeChild(sideDivInner.lastChild); - lineNumbersShown--; } } };