Beispiel #1
0
func (m MoveFOL) Apply(e *editor.Editor) {
	v := e.ActiveView()
	c := v.Cursor()
	pos := utils.IndexFirstNonSpace(c.Line.Data)
	c.Boffset = pos
	v.MoveCursorTo(c)
}
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
	}
}