3 // FromCharPos converts from a character position to an x, y position
4 func FromCharPos(loc int, buf *Buffer) Loc {
8 lineLen := Count(buf.Line(y)) + 1
9 for charNum+lineLen <= loc {
12 lineLen = Count(buf.Line(y)) + 1
19 // ToCharPos converts from an x, y position to a character position
20 func ToCharPos(start Loc, buf *Buffer) int {
21 x, y := start.X, start.Y
23 for i := 0; i < y; i++ {
24 // + 1 for the newline
25 loc += Count(buf.Line(i)) + 1
31 // Loc stores a location
36 // LessThan returns true if b is smaller
37 func (l Loc) LessThan(b Loc) bool {
41 if l.Y == b.Y && l.X < b.X {
47 // GreaterThan returns true if b is bigger
48 func (l Loc) GreaterThan(b Loc) bool {
52 if l.Y == b.Y && l.X > b.X {
58 // GreaterEqual returns true if b is greater than or equal to b
59 func (l Loc) GreaterEqual(b Loc) bool {
63 if l.Y == b.Y && l.X > b.X {
72 // LessEqual returns true if b is less than or equal to b
73 func (l Loc) LessEqual(b Loc) bool {
77 if l.Y == b.Y && l.X < b.X {
86 func (l Loc) right(buf *Buffer) Loc {
88 return Loc{l.X + 1, l.Y}
91 if l.X < Count(buf.Line(l.Y)) {
92 res = Loc{l.X + 1, l.Y}
98 func (l Loc) left(buf *Buffer) Loc {
100 return Loc{l.X - 1, l.Y}
104 res = Loc{l.X - 1, l.Y}
106 res = Loc{Count(buf.Line(l.Y - 1)), l.Y - 1}
111 func (l Loc) Move(n int, buf *Buffer) Loc {
113 for i := 0; i < n; i++ {
118 for i := 0; i < Abs(n); i++ {
124 // func (l Loc) DistanceTo(b Loc, buf *Buffer) int {