diff --git a/internal/web/static/paste-lines.js b/internal/web/static/paste-lines.js index 0eac3d3..ea4e65e 100644 --- a/internal/web/static/paste-lines.js +++ b/internal/web/static/paste-lines.js @@ -12,8 +12,10 @@ return document.documentElement.hasAttribute('data-wrap'); }; - // Wrap each logical line (split on newline; spans never contain newlines - // because HighlightCode highlights per line) in a .codeline block. + // #194: join with NO separator. .codeline is display:block, so a '\n' + // text node between spans is an extra line box in the white-space:pre + // container — that doubled the visual line spacing and desynced the + // gutter in BOTH modes. function splitLines() { var html = body.innerHTML; var parts = html.split('\n'); @@ -21,13 +23,17 @@ for (var i = 0; i < parts.length; i++) { out.push('' + parts[i] + ''); } - body.innerHTML = out.join('\n'); + body.innerHTML = out.join(''); } function renumber() { var lines = body.querySelectorAll('.codeline'); + // #194: a paste ending in '\n' produces one trailing empty .codeline; + // number only real lines (like every editor) so the count matches. + var count = lines.length; + if (count > 1 && lines[count - 1].textContent === '') count--; var s = ''; - if (wrapOn() && lines.length) { + if (wrapOn() && count) { // Each logical line block occupies rows = height / line-height when // wrapped; its number sits on the first row and the remaining rows get // blank gutter lines so numbers stay aligned with line starts. @@ -37,7 +43,7 @@ var lh = parseFloat(getComputedStyle(body).lineHeight) || 1; gutter.textContent = ''; var frag = document.createDocumentFragment(); - for (var i = 0; i < lines.length; i++) { + for (var i = 0; i < count; i++) { var num = document.createElement('span'); num.className = 'gutline'; num.textContent = String(i + 1); @@ -52,8 +58,8 @@ } gutter.appendChild(frag); } else { - for (var k = 1; k <= lines.length; k++) s += k + '\n'; - gutter.textContent = lines.length ? s.slice(0, -1) : '1'; + for (var k = 1; k <= count; k++) s += k + '\n'; + gutter.textContent = count ? s.slice(0, -1) : '1'; } }