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
This commit is contained in:
Zachary Yedidia
2020-06-23 17:17:22 -04:00
parent 9cc7c9be2d
commit 37c754c7c7

View 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])