]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/loc.go
Add cd and pwd commands to change the working dir
[micro.git] / cmd / micro / loc.go
index ce0806a17bf4d09fd6907ba37e79be6a13b5a46c..263e0fb36ad5df3a3f0d56457d162a2463a976f2 100644 (file)
@@ -28,6 +28,15 @@ func ToCharPos(start Loc, buf *Buffer) int {
        return loc
 }
 
+// InBounds returns whether the given location is a valid character position in the given buffer
+func InBounds(pos Loc, buf *Buffer) bool {
+       if pos.Y < 0 || pos.Y >= buf.NumLines || pos.X < 0 || pos.X > Count(buf.Line(pos.Y)) {
+               return false
+       }
+
+       return true
+}
+
 // 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