Skip to content

Commit fa02380

Browse files
Adding auto complete support for multi cursors
1 parent cc195b6 commit fa02380

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

internal/buffer/autocomplete.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,26 @@ func (b *Buffer) CycleAutocomplete(forward bool) {
4949
b.CurSuggestion = len(b.Suggestions) - 1
5050
}
5151

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-
}
52+
b.performAutoComplete(prevSuggestion)
5853

59-
b.Replace(start, end, b.Completions[b.CurSuggestion])
6054
if len(b.Suggestions) > 1 {
6155
b.HasSuggestions = true
6256
}
6357
}
6458

59+
func (b *Buffer) performAutoComplete(prevSuggestion int) {
60+
for _, cur := range b.cursors {
61+
curLoc := cur.Loc
62+
curStart := curLoc
63+
curEnd := curLoc
64+
65+
if prevSuggestion < len(b.Suggestions) && prevSuggestion >= 0 {
66+
curStart = curEnd.Move(-util.CharacterCountInString(b.Completions[prevSuggestion]), b)
67+
}
68+
b.Replace(curStart, curEnd, b.Completions[b.CurSuggestion])
69+
}
70+
}
71+
6572
// GetWord gets the most recent word separated by any separator
6673
// (whitespace, punctuation, any non alphanumeric character)
6774
func (b *Buffer) GetWord() ([]byte, int) {

0 commit comments

Comments
 (0)