Add some plugin functions

This commit is contained in:
Zachary Yedidia
2019-08-26 21:06:27 -04:00
parent b68461cf72
commit 6f6b263d10
2 changed files with 15 additions and 0 deletions

View File

@@ -123,3 +123,15 @@ func (l Loc) Diff(a, b Loc, buf *Buffer) int {
func (l Loc) Move(n int, buf *Buffer) Loc {
return l.MoveLA(n, buf.LineArray)
}
// ByteOffset is just like ToCharPos except it counts bytes instead of runes
func ByteOffset(pos Loc, buf *Buffer) int {
x, y := pos.X, pos.Y
loc := 0
for i := 0; i < y; i++ {
// + 1 for the newline
loc += len(buf.Line(i)) + 1
}
loc += len(buf.Line(y)[:x])
return loc
}