Implement searching

This commit is contained in:
Zachary Yedidia
2019-01-03 15:27:43 -05:00
parent f63c72c50d
commit e63a3c8917
10 changed files with 348 additions and 25 deletions

View File

@@ -188,6 +188,12 @@ func IsStrWhitespace(str string) bool {
return true
}
// RunePos returns the rune index of a given byte index
// Make sure the byte index is not between code points
func RunePos(b []byte, i int) int {
return utf8.RuneCount(b[:i])
}
// TODO: consider changing because of snap segfault
// ReplaceHome takes a path as input and replaces ~ at the start of the path with the user's
// home directory. Does nothing if the path does not start with '~'.
@@ -302,3 +308,12 @@ func GetCharPosInLine(b []byte, visualPos int, tabsize int) int {
return i
}
func Clamp(val, min, max int) int {
if val < min {
val = min
} else if val > max {
val = max
}
return val
}