Skip to content

Commit 889a841

Browse files
committed
Replaced IsNonAlphaNumeric() with IsNonWordChar()
1 parent 1f51d0b commit 889a841

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

internal/action/actions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,8 @@ func (h *BufPane) Autocomplete() bool {
745745
}
746746
r := h.Cursor.RuneUnder(h.Cursor.X)
747747
prev := h.Cursor.RuneUnder(h.Cursor.X - 1)
748-
if !util.IsAutocomplete(prev) || !util.IsNonAlphaNumeric(r) {
749-
// don't autocomplete if cursor is on alpha numeric character (middle of a word)
748+
if !util.IsAutocomplete(prev) || util.IsWordChar(r) {
749+
// don't autocomplete if cursor is within a word
750750
return false
751751
}
752752

internal/buffer/autocomplete.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ func (b *Buffer) GetWord() ([]byte, int) {
7373
return []byte{}, -1
7474
}
7575

76-
if util.IsNonAlphaNumeric(b.RuneAt(c.Loc.Move(-1, b))) {
76+
if util.IsNonWordChar(b.RuneAt(c.Loc.Move(-1, b))) {
7777
return []byte{}, c.X
7878
}
7979

80-
args := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
80+
args := bytes.FieldsFunc(l, util.IsNonWordChar)
8181
input := args[len(args)-1]
8282
return input, c.X - util.CharacterCount(input)
8383
}
@@ -166,7 +166,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
166166
var suggestions []string
167167
for i := c.Y; i >= 0; i-- {
168168
l := b.LineBytes(i)
169-
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
169+
words := bytes.FieldsFunc(l, util.IsNonWordChar)
170170
for _, w := range words {
171171
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
172172
strw := string(w)
@@ -179,7 +179,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
179179
}
180180
for i := c.Y + 1; i < b.LinesNum(); i++ {
181181
l := b.LineBytes(i)
182-
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
182+
words := bytes.FieldsFunc(l, util.IsNonWordChar)
183183
for _, w := range words {
184184
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
185185
strw := string(w)

internal/util/util.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,19 @@ func FSize(f *os.File) int64 {
218218
return fi.Size()
219219
}
220220

221-
// IsWordChar returns whether or not the string is a 'word character'
222-
// Word characters are defined as numbers, letters, or '_'
221+
// IsWordChar returns whether or not a rune is a 'word character'
222+
// Word characters are defined as numbers, letters or '_'
223223
func IsWordChar(r rune) bool {
224224
return unicode.IsLetter(r) || unicode.IsNumber(r) || r == '_'
225225
}
226226

227+
// IsNonWordChar returns whether or not a rune is not a 'word character'
228+
// Non word characters are defined as all characters not being numbers, letters or '_'
229+
// See IsWordChar()
230+
func IsNonWordChar(r rune) bool {
231+
return !IsWordChar(r)
232+
}
233+
227234
// Spaces returns a string with n spaces
228235
func Spaces(n int) string {
229236
return strings.Repeat(" ", n)
@@ -445,14 +452,9 @@ func Clamp(val, min, max int) int {
445452
return val
446453
}
447454

448-
// IsNonAlphaNumeric returns if the rune is not a number of letter or underscore.
449-
func IsNonAlphaNumeric(c rune) bool {
450-
return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '_'
451-
}
452-
453455
// IsAutocomplete returns whether a character should begin an autocompletion.
454456
func IsAutocomplete(c rune) bool {
455-
return c == '.' || !IsNonAlphaNumeric(c)
457+
return c == '.' || IsWordChar(c)
456458
}
457459

458460
// ParseSpecial replaces escaped ts with '\t'.

0 commit comments

Comments
 (0)