multi-line pasting mostly works

This commit is contained in:
Felix Angell 2018-04-21 17:57:00 +01:00
parent 44199a632f
commit 5bd152e44c
2 changed files with 15 additions and 3 deletions

View File

@ -109,12 +109,24 @@ func (b *Buffer) OnInit() {}
func (b *Buffer) appendLine(val string) {
b.contents = append(b.contents, rope.New(val))
// because we've added a new line
// we have to set the x to the start
b.curs.x = 0
}
// inserts a string, handling all of the newlines etc
func (b *Buffer) insertString(idx int, val string) {
lines := strings.Split(val, "\n")
for _, l := range lines {
b.contents = append(b.contents, new(rope.Rope))
copy(b.contents[b.curs.y+idx+1:], b.contents[b.curs.y+idx:])
b.contents[b.curs.y+idx] = rope.New(l)
b.moveDown()
}
}
func (b *Buffer) insertRune(r rune) {
log.Println("Inserting rune ", r, " into current line at ", b.curs.x, ":", b.curs.y)
log.Println("Line before insert> ", b.contents[b.curs.y])

View File

@ -9,9 +9,9 @@ import (
func Paste(b *Buffer) bool {
str, err := clipboard.ReadAll()
if err == nil {
b.contents[b.curs.y] = b.contents[b.curs.y].Insert(b.curs.x, str)
b.insertString(b.curs.x, str)
b.moveToEndOfLine()
return true
}