Skip to content

Commit

Permalink
fix(add-remove-comment): fixed line ending
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed May 19, 2023
1 parent 555817c commit 8950d4d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/commands/addRemoveComment/addRemoveComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ export class AddRemoveCommentCommand {
if (activeEditor) {
const { start, end } = activeEditor.selection
const text = activeEditor.document.getText()
const lines = text.split(`\n`) || []

enum LineEndings {
CRLF = `\r\n`,
LF = `\n`
}
const lineEnding = new RegExp(LineEndings.CRLF + `$`).test(text)
? LineEndings.CRLF
: LineEndings.LF

const lines = text.split(lineEnding) || []

const editedLines = lines
.reduce((acc: string[], line: string, i: number) => {
Expand All @@ -65,7 +74,7 @@ export class AddRemoveCommentCommand {

return acc
}, [])
.join(`\n`)
.join(lineEnding)

// INFO: exit point for unit test
if (mockedActiveEditor) {
Expand Down

0 comments on commit 8950d4d

Please sign in to comment.