From 37c754c7c7a4d5817b54799d665d49d29833b9e9 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Tue, 23 Jun 2020 17:17:22 -0400 Subject: [PATCH] Treat CRLF as LF when inserting text In effect, pasting text with \r\n will remove the \r character and delegate whether or not the file will be saved with CRLF or LF line endings to the `fileformat` option. Ref #1742 --- internal/buffer/line_array.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/buffer/line_array.go b/internal/buffer/line_array.go index 716107e1..717a9c00 100644 --- a/internal/buffer/line_array.go +++ b/internal/buffer/line_array.go @@ -191,10 +191,15 @@ func (la *LineArray) newlineBelow(y int) { func (la *LineArray) insert(pos Loc, value []byte) { x, y := runeToByteIndex(pos.X, la.lines[pos.Y].data), pos.Y for i := 0; i < len(value); i++ { - if value[i] == '\n' { + if value[i] == '\n' || (value[i] == '\r' && i < len(value)-1 && value[i+1] == '\n') { la.split(Loc{x, y}) x = 0 y++ + + if value[i] == '\r' { + i++ + } + continue } la.insertByte(Loc{x, y}, value[i])