mirror of https://github.com/jroimartin/gocui.git
Fix View.Word()
This commit is contained in:
parent
f51a568142
commit
7cc82f809e
10
view.go
10
view.go
|
@ -262,13 +262,13 @@ func (v *View) Word(x, y int) (string, error) {
|
||||||
return "", errors.New("invalid point")
|
return "", errors.New("invalid point")
|
||||||
}
|
}
|
||||||
l := string(v.lines[y])
|
l := string(v.lines[y])
|
||||||
nl := strings.LastIndex(l[:x], " ")
|
nl := strings.LastIndexFunc(l[:x], indexFunc)
|
||||||
if nl == -1 {
|
if nl == -1 {
|
||||||
nl = 0
|
nl = 0
|
||||||
} else {
|
} else {
|
||||||
nl = nl + 1
|
nl = nl + 1
|
||||||
}
|
}
|
||||||
nr := strings.Index(l[x:], " ")
|
nr := strings.IndexFunc(l[x:], indexFunc)
|
||||||
if nr == -1 {
|
if nr == -1 {
|
||||||
nr = len(l)
|
nr = len(l)
|
||||||
} else {
|
} else {
|
||||||
|
@ -276,3 +276,9 @@ func (v *View) Word(x, y int) (string, error) {
|
||||||
}
|
}
|
||||||
return string(l[nl:nr]), nil
|
return string(l[nl:nr]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// indexFunc allows to split lines by words taking into account spaces
|
||||||
|
// and 0
|
||||||
|
func indexFunc(r rune) bool {
|
||||||
|
return r == ' ' || r == 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue