Exemple #1
0
// VoffsetCoffset returns a visual and a character offset for a given cursor.
func (c *Cursor) VoffsetCoffset() (vo, co int) {
	data := c.Line.Data[:c.Boffset]
	for len(data) > 0 {
		r, rlen := utf8.DecodeRune(data)
		data = data[rlen:]
		co += 1
		vo += utils.RuneAdvanceLen(r, vo)
	}
	return
}
Exemple #2
0
// Find a set of closest offsets for a given visual offset
func (l *Line) FindClosestOffsets(voffset int) (bo, co, vo int) {
	data := l.Data
	for len(data) > 0 {
		var vodif int
		r, rlen := utf8.DecodeRune(data)
		data = data[rlen:]
		vodif = utils.RuneAdvanceLen(r, vo)
		if vo+vodif > voffset {
			return
		}

		bo += rlen
		co += 1
		vo += vodif
	}
	return
}