fix(completion_preview.lua): fix for cursor position for multi line completions #7
No reviewers
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
supermaven-inc/supermaven-nvim!7
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "multiline-issue"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The main change is at the end of the
CompletionPreview.on_accept_suggestion(), I calculate the new cursor position based on the number of lines in thecompletion_text.So I just:
Setting the cursor position using
nvim_win_set_cursor()is a more standard approach, especially if users have certain keybindings for specific keys compared to PR #2.This fixes Issue #2.
Using this branch:

The problem with multi-line suggestions is resolved. Meaning, after accepting a multi-line suggestion the cursor moves correctly. But in other cases where the suggestion is on the line, it's completely broken.




1.
2. Accepted with Tab:
3. Accepted with Tab again:
4. Accepted with Tab again:
@amirhhashemi You're right. We have a fix in the discord for it. I'm sure he will add it to the PR soon.
Yep, we already have a fix, it does the completion but moves it to a weird spot. I will make the PR now.
Edit: done, it is fixed now!
The new commit fixed it. LGTM.
Can be merged now, Issue #2 is resolved @super-jacob!
This looks good. I'll wait for @victorw-xyz's review before merging.
Added a fix for
get_uft8_length()using neovim's built-invim.fn.strlen()This solves issue #2 without having to check for specific versions of Neovim, which is nice, as we won't have to continue updating this logic
I was running into the 8000-char limit as well and ended up on this PR.
I question whether using
vim.fn.strlen()or the otherstring.byte()method is necessary at all. Lua'sstring.len()/#operator already return the byte length of strings with multi-byte characters, the same as the originalstring.byte()implementation andvim.fn.strlen():The same can be said for other multi-byte characters, like
€(3) andñ(2).Why not just use
#? Should be able to ditchutil.get_utf8_lengthand then do:Correct, just verified it. I think

#strandstr:len()are the same thing, and#stris much faster thanstrlen():I changed
vim.fn.strlen(str)to#stras that is indeed much faster (thanks @b0o and @3rd). As for getting rid of the util function itself, I leave that up to @victorw-xyz.With this everything should be taken care of now. I think it can be merged now @super-jacob?
Thanks for fixing this, this issue has made it completely unusable for me in the meantime