Fix display of completion on wrapped lines #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 usingvirt_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 thevirtcol('.')
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 setnumber
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
, usingoverlay
by default to overwrite the text currently on the line which the code will replace anyway, oreol
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 emptyl: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 withl: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.