MCPcopy
hub / github.com/micro-editor/micro / CycleAutocomplete

Method CycleAutocomplete

internal/buffer/autocomplete.go:38–63  ·  view source on GitHub ↗

CycleAutocomplete moves to the next suggestion

(forward bool)

Source from the content-addressed store, hash-verified

36
37// CycleAutocomplete moves to the next suggestion
38func (b *Buffer) CycleAutocomplete(forward bool) {
39 prevSuggestion := b.CurSuggestion
40
41 if forward {
42 b.CurSuggestion++
43 } else {
44 b.CurSuggestion--
45 }
46 if b.CurSuggestion >= len(b.Suggestions) {
47 b.CurSuggestion = 0
48 } else if b.CurSuggestion < 0 {
49 b.CurSuggestion = len(b.Suggestions) - 1
50 }
51
52 c := b.GetActiveCursor()
53 start := c.Loc
54 end := c.Loc
55 if prevSuggestion < len(b.Suggestions) && prevSuggestion >= 0 {
56 start = end.Move(-util.CharacterCountInString(b.Completions[prevSuggestion]), b)
57 }
58
59 b.Replace(start, end, b.Completions[b.CurSuggestion])
60 if len(b.Suggestions) > 1 {
61 b.HasSuggestions = true
62 }
63}
64
65// GetWord gets the most recent word separated by any separator
66// (whitespace, punctuation, any non alphanumeric character)

Callers 4

AutocompleteMethod · 0.95
CommandCompleteMethod · 0.80
AutocompleteMethod · 0.80
CycleAutocompleteBackMethod · 0.80

Calls 4

GetActiveCursorMethod · 0.95
CharacterCountInStringFunction · 0.92
MoveMethod · 0.80
ReplaceMethod · 0.80

Tested by

no test coverage detected