From 80568c53264b210246bb5ab2bb28424f90233632 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Wed, 8 Feb 2017 19:11:42 -0800 Subject: [PATCH] remove the new line after targeted line --- src/services/codefixes/unusedIdentifierFixes.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/services/codefixes/unusedIdentifierFixes.ts b/src/services/codefixes/unusedIdentifierFixes.ts index 0ca01a81eb1..3e74f81d8aa 100644 --- a/src/services/codefixes/unusedIdentifierFixes.ts +++ b/src/services/codefixes/unusedIdentifierFixes.ts @@ -150,7 +150,20 @@ namespace ts.codefix { } function createCodeFixToRemoveNode(node: Node) { - return createCodeFix("", node.getStart(), node.getWidth()); + let end = node.getEnd(); + const endCharCode = sourceFile.text.charCodeAt(end); + const afterEndCharCode = sourceFile.text.charCodeAt(end + 1); + if (isLineBreak(endCharCode)) { + end += 1; + } + // in the case of CR LF, you could have two consecutive new line characters for one new line. + // this needs to be differenciated from two LF LF chars that actually mean two new lines. + if (isLineBreak(afterEndCharCode) && endCharCode !== afterEndCharCode) { + end += 1; + } + + const start = node.getStart(); + return createCodeFix("", start, end - start); } function findFirstNonSpaceCharPosStarting(start: number) {