-// FromCharPos converts from a character position to an x, y position
-func FromCharPos(loc int, buf *Buffer) (int, int) {
- return FromCharPosStart(0, 0, 0, loc, buf)
-}
-
-// FromCharPosStart converts from a character position to an x, y position, starting at the specified character location
-func FromCharPosStart(startLoc, startX, startY, loc int, buf *Buffer) (int, int) {
- charNum := startLoc
- x, y := startX, startY
-
- lineLen := Count(buf.Lines[y]) + 1
- for charNum+lineLen <= loc {
- charNum += lineLen
- y++
- if y >= buf.NumLines {
- return 0, 0
- }
- lineLen = Count(buf.Lines[y]) + 1
- }
- x = loc - charNum
-
- return x, y
-}
-
-// ToCharPos converts from an x, y position to a character position
-func ToCharPos(x, y int, buf *Buffer) int {
- loc := 0
- for i := 0; i < y; i++ {
- // + 1 for the newline
- loc += Count(buf.Lines[i]) + 1
- }
- loc += x
- return loc
-}
-