Skip to content

Commit

Permalink
Discard carriage return when loading file
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Apr 30, 2024
1 parent 71f59a0 commit 2a78d1a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/text/text_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,15 @@ proc `content=`*(self: TextDocument, value: string) =
var newLine = value.find('\n', start=index)
self.lines = @[""]
while newLine != -1:
let newLineStart = if newLine > 0 and value[newLine - 1] == '\r':
newLine - 1
else:
newLine

if self.singleLine:
self.lines[0].add value[index..<newLine]
self.lines[0].add value[index..<newLineStart]
else:
self.lines[self.lines.high] = value[index..<newLine]
self.lines[self.lines.high] = value[index..<newLineStart]
self.lines.add ""

index = newLine + 1
Expand Down

0 comments on commit 2a78d1a

Please sign in to comment.