Beispiel #1
0
func (v *View) yank() {
	buf := *v.ctx.killBuffer
	cursor := v.cursor

	if len(buf) == 0 {
		return
	}
	cbuf := utils.CloneByteSlice(buf)
	v.buf.Insert(cursor, cbuf)
	for len(buf) > 0 {
		_, rlen := utf8.DecodeRune(buf)
		buf = buf[rlen:]
		cursor.NextRune(true)
	}
	v.MoveCursorTo(cursor)
}
Beispiel #2
0
// InsertRune inserts 'r' at the cursor position 'c'
func (b *Buffer) InsertRune(c Cursor, r rune) {
	if r == '\n' || r == '\r' {
		b.Insert(c, []byte{'\n'})
		prev := c.Line
		c.Line = c.Line.Next
		c.LineNum++
		c.Boffset = 0

		if r == '\n' {
			i := utils.IndexFirstNonSpace(prev.Data)
			if i > 0 {
				autoindent := utils.CloneByteSlice(prev.Data[:i])
				b.Insert(c, autoindent)
				c.Boffset += len(autoindent)
			}
		}
	} else {
		var data [utf8.UTFMax]byte
		nBytes := utf8.EncodeRune(data[:], r)
		b.Insert(c, data[:nBytes])
		c.Boffset += nBytes
	}
}