Skip to content

Commit

Permalink
Fix View.Word()
Browse files Browse the repository at this point in the history
  • Loading branch information
jroimartin committed Jan 23, 2014
1 parent f51a568 commit 7cc82f8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,23 @@ func (v *View) Word(x, y int) (string, error) {
return "", errors.New("invalid point")
}
l := string(v.lines[y])
nl := strings.LastIndex(l[:x], " ")
nl := strings.LastIndexFunc(l[:x], indexFunc)
if nl == -1 {
nl = 0
} else {
nl = nl + 1
}
nr := strings.Index(l[x:], " ")
nr := strings.IndexFunc(l[x:], indexFunc)
if nr == -1 {
nr = len(l)
} else {
nr = nr + x
}
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
}

0 comments on commit 7cc82f8

Please sign in to comment.