From 79ee757757cfe5d88aa3bd647c09ccd2c374272b Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 8 Jun 2020 13:54:31 -0400 Subject: [PATCH] Only start autocompletion for alphanumerics Ref #1712 --- internal/action/actions.go | 7 ++++++- internal/util/util.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index 6f2f0940..9cff5de3 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -663,7 +663,12 @@ func (h *BufPane) Autocomplete() bool { return false } - if !util.IsNonAlphaNumeric(h.Cursor.RuneUnder(h.Cursor.X)) { + if h.Cursor.X == 0 { + return false + } + 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) return false } diff --git a/internal/util/util.go b/internal/util/util.go index a63a3518..8b867ca0 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -418,6 +418,10 @@ func IsNonAlphaNumeric(c rune) bool { return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '_' } +func IsAutocomplete(c rune) bool { + return c == '.' || !IsNonAlphaNumeric(c) +} + func ParseSpecial(s string) string { return strings.Replace(s, "\\t", "\t", -1) }