]> git.lizzy.rs Git - micro.git/commitdiff
Treat CRLF as LF when inserting text
authorZachary Yedidia <zyedidia@gmail.com>
Tue, 23 Jun 2020 21:17:22 +0000 (17:17 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Tue, 23 Jun 2020 21:17:22 +0000 (17:17 -0400)
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

index 716107e1155ec877fd5c32417a2557f846fc3fc7..717a9c002a6a279ed6c9ce60791518d4d6ee3eeb 100644 (file)
@@ -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])