mirror of
https://github.com/felixangell/phi.git
synced 2024-08-16 19:20:21 +03:00
multi-line pasting mostly works
This commit is contained in:
parent
44199a632f
commit
5bd152e44c
@ -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])
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user