From c8152636711600ccdd5d7402d2aeef31193bfb84 Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 18 Mar 2017 02:05:58 +0300 Subject: [PATCH] moz-import: don't add an extra newline before the last line --- edit.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/edit.js b/edit.js index 4b439e07..d07c759f 100644 --- a/edit.js +++ b/edit.js @@ -1364,7 +1364,7 @@ function fromMozillaFormat() { section.code = gapComment[1] + "\n"; outerText = trimNewLines(outerText.substring(0, gapComment.index)); } - if (outerText) { + if (outerText.trim()) { sectionStack.last.code = outerText; doAddSection(sectionStack.last); sectionStack.last.code = ""; @@ -1411,13 +1411,15 @@ function fromMozillaFormat() { parser.parse(mozStyle); - function getRange(start, end) { - if (start.line == end.line) { - return lines[start.line - 1].substr(start.col - 1, end.col - start.col + 1).trim(); + function getRange( start, end) { + const L1 = start.line - 1, C1 = start.col - 1; + const L2 = end.line - 1, C2 = end.col - 1; + if (L1 == L2) { + return lines[L1].substr(C1, C2 - C1 + 1); } else { - return trimNewLines(lines[start.line - 1].substr(start.col - 1) + "\n" + - lines.slice(start.line, end.line - 1).join("\n") + - "\n" + lines[end.line - 1].substring(0, end.col - 1)); + const middle = lines.slice(L1 + 1, L2).join('\n'); + return lines[L1].substr(C1) + '\n' + middle + + (L2 >= lines.length ? '' : ((middle ? '\n' : '') + lines[L2].substring(0, C2))); } } function doAddSection(section) {