Replaced IsNonAlphaNumeric() with IsNonWordChar()
This commit is contained in:
parent
1f51d0b9e2
commit
889a841575
3 changed files with 16 additions and 14 deletions
|
@ -745,8 +745,8 @@ func (h *BufPane) Autocomplete() bool {
|
|||
}
|
||||
r := h.Cursor.RuneUnder(h.Cursor.X)
|
||||
prev := h.Cursor.RuneUnder(h.Cursor.X - 1)
|
||||
if !util.IsAutocomplete(prev) || !util.IsNonAlphaNumeric(r) {
|
||||
// don't autocomplete if cursor is on alpha numeric character (middle of a word)
|
||||
if !util.IsAutocomplete(prev) || util.IsWordChar(r) {
|
||||
// don't autocomplete if cursor is within a word
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -73,11 +73,11 @@ func (b *Buffer) GetWord() ([]byte, int) {
|
|||
return []byte{}, -1
|
||||
}
|
||||
|
||||
if util.IsNonAlphaNumeric(b.RuneAt(c.Loc.Move(-1, b))) {
|
||||
if util.IsNonWordChar(b.RuneAt(c.Loc.Move(-1, b))) {
|
||||
return []byte{}, c.X
|
||||
}
|
||||
|
||||
args := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
|
||||
args := bytes.FieldsFunc(l, util.IsNonWordChar)
|
||||
input := args[len(args)-1]
|
||||
return input, c.X - util.CharacterCount(input)
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
|
|||
var suggestions []string
|
||||
for i := c.Y; i >= 0; i-- {
|
||||
l := b.LineBytes(i)
|
||||
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
|
||||
words := bytes.FieldsFunc(l, util.IsNonWordChar)
|
||||
for _, w := range words {
|
||||
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
|
||||
strw := string(w)
|
||||
|
@ -179,7 +179,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
|
|||
}
|
||||
for i := c.Y + 1; i < b.LinesNum(); i++ {
|
||||
l := b.LineBytes(i)
|
||||
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
|
||||
words := bytes.FieldsFunc(l, util.IsNonWordChar)
|
||||
for _, w := range words {
|
||||
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
|
||||
strw := string(w)
|
||||
|
|
|
@ -218,12 +218,19 @@ func FSize(f *os.File) int64 {
|
|||
return fi.Size()
|
||||
}
|
||||
|
||||
// IsWordChar returns whether or not the string is a 'word character'
|
||||
// Word characters are defined as numbers, letters, or '_'
|
||||
// IsWordChar returns whether or not a rune is a 'word character'
|
||||
// Word characters are defined as numbers, letters or '_'
|
||||
func IsWordChar(r rune) bool {
|
||||
return unicode.IsLetter(r) || unicode.IsNumber(r) || r == '_'
|
||||
}
|
||||
|
||||
// IsNonWordChar returns whether or not a rune is not a 'word character'
|
||||
// Non word characters are defined as all characters not being numbers, letters or '_'
|
||||
// See IsWordChar()
|
||||
func IsNonWordChar(r rune) bool {
|
||||
return !IsWordChar(r)
|
||||
}
|
||||
|
||||
// Spaces returns a string with n spaces
|
||||
func Spaces(n int) string {
|
||||
return strings.Repeat(" ", n)
|
||||
|
@ -445,14 +452,9 @@ func Clamp(val, min, max int) int {
|
|||
return val
|
||||
}
|
||||
|
||||
// IsNonAlphaNumeric returns if the rune is not a number of letter or underscore.
|
||||
func IsNonAlphaNumeric(c rune) bool {
|
||||
return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '_'
|
||||
}
|
||||
|
||||
// IsAutocomplete returns whether a character should begin an autocompletion.
|
||||
func IsAutocomplete(c rune) bool {
|
||||
return c == '.' || !IsNonAlphaNumeric(c)
|
||||
return c == '.' || IsWordChar(c)
|
||||
}
|
||||
|
||||
// ParseSpecial replaces escaped ts with '\t'.
|
||||
|
|
Loading…
Reference in a new issue