Add multicursor autocompletions - #4028
Conversation
|
But we already have #3442 and this use case is discussed within it?! |
|
Yes, but #3442 still autocompletes on all cursors, even if they shouldn't be. |
|
Tested the changes, works well as expected. Nice one. |
|
Hey @redsti-github , I want to merge this to my own fork. Could you tidy up the commits please? Thanks. |
325e85c to
5c71c2e
Compare
| // (whitespace, punctuation, any non alphanumeric character) | ||
| func (b *Buffer) GetWord() ([]byte, int) { | ||
| c := b.GetActiveCursor() | ||
| func (b *Buffer) GetWordCursor(c *Cursor) ([]byte, int) { |
There was a problem hiding this comment.
Why not make it a method of Cursor?
| continue | ||
| } | ||
|
|
||
| activeWord, _ := b.GetWordCursor(b.GetActiveCursor()) |
There was a problem hiding this comment.
We can get activeWord once before the loop, instead of recalculating it on each iteration?
BTW then we don't need to postpone autocompleting the active cursor until after the loop, we can do it before the loop... but only with an extra change like this:
--- a/internal/buffer/autocomplete.go
+++ b/internal/buffer/autocomplete.go
@@ -115,7 +116,7 @@ func (b *Buffer) GetWordCursor(c *Cursor) ([]byte, int) {
}
args := bytes.FieldsFunc(l, util.IsNonWordChar)
- input := args[len(args)-1]
+ input := bytes.Clone(args[len(args)-1])
return input, c.X - util.CharacterCount(input)
}Hmm, maybe an extra change like this would be good to apply anyway?
| } | ||
|
|
||
| activeWord, _ := b.GetWordCursor(b.GetActiveCursor()) | ||
| word, _ := b.GetWordCursor(c); |
There was a problem hiding this comment.
Unneeded semicolon (see gofmt)
There was a problem hiding this comment.
Damn, this must be automatically found and not every time by you within the review! 😓
-> #4175
| } | ||
| } | ||
|
|
||
| func (b *Buffer) AutocompleteSingle(c *Cursor, prevSuggestion int) { |
There was a problem hiding this comment.
Do we need this function to be public? I'm not sure we want to expose this low-level function to plugins...
So maybe name it e.g. just autocomplete() (lowercase)?
Implements autocomplete while using multiple cursors. (loosely based on #3442)
Only autocompletes cursors which end in the same word as the active cursor.
For example:
Closes #3442