diff --git a/gui/buffer.go b/gui/buffer.go index e200bd5..50ecf73 100644 --- a/gui/buffer.go +++ b/gui/buffer.go @@ -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]) diff --git a/gui/shortcuts.go b/gui/shortcuts.go index 4b671de..191f158 100644 --- a/gui/shortcuts.go +++ b/gui/shortcuts.go @@ -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 }