Skip to content

Fix display of completion on wrapped lines #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jamesb6626
Copy link
Contributor

@jamesb6626 jamesb6626 commented Jun 7, 2025

This partially resolves #69, allowing the completion to display on the current line of the cursor in soft-wrapped text.

Previously, l:pos_x gave the completion roughly correct position, but then using virt_text_win_col to nudge it a little prevented display with the cursor on anything but the first screen-line of a wrapped line, since the virtcol('.') function does not respect wrapping, nor does any other nvim api function, at least not in the way that is needed, other functions have problems if you set number and so on.

Basically, we used to draw it offscreen in the described case, in a column past the edge of the screen, and that way of positioning seems hard to fix.

We could add all sorts of logic for number and sign columns, but it seems easier and seems to work to just to nudge the mark right by one, then position using virt_text_pos, using overlay by default to overwrite the text currently on the line which the code will replace anyway, or eol if there's no actual completion so that the generation info of blank output doesn't uselessly overwrite the text on screen.

Note that this won't clear the suffix of a line that might become cleared in a multiline completion, it will just draw the completion info over the top, so the old text might peek out underneath if it's longer. But then neither did the old code afaict, so this should behave the same.

Please note that I have not extensively tested this, just the obvious checks that I can do, so someone who knows better than me should probably have a check before this is merged, but it works for me and I see no reason why this shouldn't be correct.

This also still doesn't allow wrapping the completion. As a future enhancement not covered in this pull request, I think we could switch to inline to get the completion itself to wrap, in the limited case where there's one line of content and an empty l:line_cur_suffix (cursor at end of line). This would nudge the proceeding code about on the user's screen and so this should be optional for users who restrict completion to a single line, which is why I've left that out for now. But I'd probably optionally precede the condition with l:line_cur_suffix == "" ? 'inline' : ....

Note that I also removed the virt_text_win_col parameter from the code that deals with the subsequent lines, as that parameter seems redundant because it renders as virt_lines rather than virt_text. Someone correct me if I'm wrong.

Offset the mark by one, use `virt_text_pos` instead of `virt_text_pos`.

Using `virt_text_win_col` seems hard to get right, would need to wrap
around from 0 on the next line in wrapped text else we draw offscreen.
Which is then complicated by adjustments to the width of the text due to
sign columns, number columns, etc.

Using `virt_text_pos` works better with the cursor on wrapped lines.
I think this is virt_lines rather than virt_text, so this does nothing.
But if it did anything in the first place, I think it would be wrong.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Completion does not display on wrapped lines
1 participant