CycleAutocomplete moves to the next suggestion
(forward bool)
| 36 | |
| 37 | // CycleAutocomplete moves to the next suggestion |
| 38 | func (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) |
no test coverage detected