Skip to content

Commit 17335e3

Browse files
Merge branch 'autocomplete-fix' into dev
2 parents c93d951 + d5d9127 commit 17335e3

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

internal/action/actions.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
"time"
1212

1313
shellquote "github.com/kballard/go-shellquote"
14+
"github.com/micro-editor/tcell/v2"
1415
"github.com/zyedidia/micro/v2/internal/buffer"
1516
"github.com/zyedidia/micro/v2/internal/clipboard"
1617
"github.com/zyedidia/micro/v2/internal/config"
1718
"github.com/zyedidia/micro/v2/internal/display"
1819
"github.com/zyedidia/micro/v2/internal/screen"
1920
"github.com/zyedidia/micro/v2/internal/shell"
2021
"github.com/zyedidia/micro/v2/internal/util"
21-
"github.com/micro-editor/tcell/v2"
2222
)
2323

2424
// ScrollUp is not an action
@@ -901,19 +901,17 @@ func (h *BufPane) OutdentSelection() bool {
901901
// Autocomplete cycles the suggestions and performs autocompletion if there are suggestions
902902
func (h *BufPane) Autocomplete() bool {
903903
b := h.Buf
904+
cc := buffer.AutocompleteCursorCheck(h.Cursor)
905+
rc := buffer.AutocompleteRuneCheck(h.Cursor)
904906

905907
// Don't autocomplete at all if the active cursor cannot be autocomplete
906-
if !buffer.AutocompleteCheck(h.Cursor) {
907-
return false
908-
}
909-
910-
if !b.HasSuggestions && !b.StartAutocomplete(buffer.BufferComplete) {
908+
if !b.HasSuggestions && (!rc || !cc || !b.StartAutocomplete(buffer.BufferComplete)) {
911909
return false
912910
}
913911

914912
prevSuggestion := b.CycleAutocomplete(true)
915913
for i := 0; i < b.NumCursors(); i++ {
916-
if buffer.AutocompleteCheck(b.GetCursor(i)) {
914+
if buffer.AutocompleteCursorCheck(b.GetCursor(i)) {
917915
b.PerformSingleAutocomplete(prevSuggestion, b.GetCursor(i))
918916
}
919917
}
@@ -931,7 +929,7 @@ func (h *BufPane) CycleAutocompleteBack() bool {
931929
if b.HasSuggestions {
932930
prevSuggestion := b.CycleAutocomplete(false)
933931
for i := 0; i < b.NumCursors(); i++ {
934-
if buffer.AutocompleteCheck(b.GetCursor(i)) {
932+
if buffer.AutocompleteCursorCheck(b.GetCursor(i)) {
935933
b.PerformSingleAutocomplete(prevSuggestion, b.GetCursor(i))
936934
}
937935
}

internal/action/infopane.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package action
33
import (
44
"bytes"
55

6+
"github.com/micro-editor/tcell/v2"
67
"github.com/zyedidia/micro/v2/internal/buffer"
78
"github.com/zyedidia/micro/v2/internal/config"
89
"github.com/zyedidia/micro/v2/internal/display"
910
"github.com/zyedidia/micro/v2/internal/info"
1011
"github.com/zyedidia/micro/v2/internal/util"
11-
"github.com/micro-editor/tcell/v2"
1212
)
1313

1414
type InfoKeyAction func(*InfoPane)
@@ -193,11 +193,19 @@ func (h *InfoPane) CommandComplete() {
193193
b := h.Buf
194194
c := b.GetActiveCursor()
195195

196+
cc := buffer.AutocompleteCursorCheck(c)
197+
rc := buffer.AutocompleteRuneCheck(c)
198+
196199
// Cycling commands
197-
if !buffer.AutocompleteCheck(c) {
200+
if !b.HasSuggestions && !cc && !rc {
198201
return
199202
}
203+
200204
if b.HasSuggestions {
205+
if !cc {
206+
return
207+
}
208+
201209
prevSuggestion := b.CycleAutocomplete(true)
202210
b.PerformSingleAutocomplete(prevSuggestion, c)
203211
return

internal/buffer/autocomplete.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ func (b *Buffer) GetSuggestions() {
2323

2424
}
2525

26-
func AutocompleteCheck(cursor *Cursor) bool {
27-
if cursor.HasSelection() {
28-
return false
29-
}
30-
if cursor.X == 0 {
31-
return false
32-
}
26+
func AutocompleteRuneCheck(cursor *Cursor) bool {
3327
r := cursor.RuneUnder(cursor.X)
3428
prev := cursor.RuneUnder(cursor.X - 1)
3529
if !util.IsAutocomplete(prev) || util.IsWordChar(r) {
@@ -39,6 +33,16 @@ func AutocompleteCheck(cursor *Cursor) bool {
3933
return true
4034
}
4135

36+
func AutocompleteCursorCheck(cursor *Cursor) bool {
37+
if cursor.HasSelection() {
38+
return false
39+
}
40+
if cursor.X == 0 {
41+
return false
42+
}
43+
return true
44+
}
45+
4246
func (b *Buffer) StartAutocomplete(c Completer) bool {
4347
b.Completions, b.Suggestions = c(b)
4448
if len(b.Completions) != len(b.Suggestions) || len(b.Completions) == 0 {

0 commit comments

Comments
 (0)