Skip to content
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

feat(screen): virtual lines #15351

Merged
merged 1 commit into from
Sep 26, 2021
Merged

feat(screen): virtual lines #15351

merged 1 commit into from
Sep 26, 2021

Conversation

bfredl
Copy link
Member

@bfredl bfredl commented Aug 12, 2021

Note: probably not the final api. But for now

vim.api.nvim_buf_set_extmark(0, ns, 5, 0, {virt_lines={{{'line 1', 'String'}}, {{'line 2 ', 'ErrorMsg'}, {'text','LineNr'}}, }})

Limitation: only one (1) block of virtual lines per buffer! To enable quick prototyping. we can lift this limitation later.

@bew
Copy link
Sponsor Contributor

bew commented Aug 12, 2021

The title of this PR means something awesome!
Could you share screenshots of how it looks like, as you work on this? 🙏

@bfredl
Copy link
Member Author

bfredl commented Aug 12, 2021

Screenshot from 2021-08-12 15-47-53

@bfredl
Copy link
Member Author

bfredl commented Aug 12, 2021

TODO item: set wd=50 rdb=compositor,nodelta number relativenumber

@bfredl
Copy link
Member Author

bfredl commented Aug 19, 2021

added options: virt_lines_above and virt_lines_signcol

TODO: cannot display virt_lines below last line. (above first line works, need to scroll up tho after adding)

@resolritter
Copy link
Contributor

Please correct me if I'm wrong, but I think this could be used for the use-case mentioned in #9496 (comment) (linked Reddit post: https://www.reddit.com/r/neovim/comments/ieh7l4/im_building_an_image_plugin_and_need_some_help/).

I imagine it would enable plugins such as https://github.com/heapslip/vimage.nvim and https://github.com/edluffy/hologram.nvim to make virtual space for displaying images without tampering with the buffer. Is this assumption correct?

@dccsillag
Copy link

As I understand it, yes. On the same line, it would also be quite helful in https://github.com/dccsillag/magma-nvim in order to have output windows which do not cover any of the buffer text.

@bfredl bfredl force-pushed the virt_line branch 4 times, most recently from b65f333 to 4cf1133 Compare September 16, 2021 21:21
@bfredl bfredl marked this pull request as ready for review September 16, 2021 21:21
@bfredl bfredl force-pushed the virt_line branch 3 times, most recently from 918e46f to 4c87abe Compare September 22, 2021 13:52
@adelarsq
Copy link

@dccsillag Would be amazing! Also can be useful for VCS tools.

@bfredl bfredl force-pushed the virt_line branch 2 times, most recently from 5825838 to f343f5d Compare September 22, 2021 17:52
@roland-5

This comment has been minimized.

@max397574
Copy link
Contributor

Can someone give an example for this
I tried lua vim.api.nvim_buf_set_extmark(0, ns, 5, 0, {virt_lines={{{'line 1', 'String'}}, {{'line 2 ', 'ErrorMsg'}, {'text','LineNr'}}, }}) (from bfredl above)
but got this
Screen Shot 2021-09-26 at 19 14 54

@vhyrro
Copy link

vhyrro commented Sep 26, 2021

@max397574 make sure that ns is a valid variable that holds a namespace id :)

@dccsillag
Copy link

dccsillag commented Sep 26, 2021

@max397574

:lua ns = vim.api.nvim_create_namespace('virtline_testing')
:lua vim.api.nvim_buf_set_extmark(vim.fn.bufnr(), ns, 2, 1, {virt_lines={{{'line 1', 'Comment'}}, {{'line 2;', 'Comment'}}}})

Note the double braces on the virt_lines stuff.

@dccsillag
Copy link

dccsillag commented Sep 26, 2021

Cursor movement seems to remove the virtual lines for me. Does anyone else also experience this?

Update: doesn't happen with nvim -u NONE. Probably an autocommand then, but probably an issue -- I'll try to single it out.

@dccsillag
Copy link

Weird, I can't reproduce it anymore.

@Shougo
Copy link
Contributor

Shougo commented Sep 27, 2021

I have tested with echodoc. But it seems broken with native popup menu.

スクリーンショット_2021-09-27_10-34-37

When I select the candidate

スクリーンショット_2021-09-27_10-35-54

@Shougo
Copy link
Contributor

Shougo commented Sep 27, 2021

The original popup menu with text.

スクリーンショット_2021-09-27_10-37-07

@bfredl
Copy link
Member Author

bfredl commented Sep 27, 2021

@Shougo is there a branch somewhere with the actual code? otherwise I cannot reproduce.

@Shougo
Copy link
Contributor

Shougo commented Sep 27, 2021

I have pushed code.

I have tested echodoc master branch with the config.

let g:echodoc#type = has('nvim') ? 'virtual_lines' : 'popup'
call echodoc#enable()

@Shougo
Copy link
Contributor

Shougo commented Sep 27, 2021

I have tested it with ddc.vim neco-vim echodoc with Vim script editing.

@bfredl
Copy link
Member Author

bfredl commented Sep 27, 2021

that... sounds like a lot of stuff to setup and many layers to debug. maybe I will check it later.

@zeertzjq
Copy link
Member

zeertzjq commented Oct 5, 2021

Cursor movement seems to remove the virtual lines for me. Does anyone else also experience this?

Update: doesn't happen with nvim -u NONE. Probably an autocommand then, but probably an issue -- I'll try to single it out.

I am also encountering this issue. This happens very frequently with vim-matchup's matchparen feature. If I run autocmd! matchup_matchparen to remove matchup_matchparen autocmds, then it happens less frequently, but it still sometimes happens.

@mrossinek
Copy link

I'm not sure about a better place to ask this, so I'll just do that here: do you plan on supporting some sort of cursor navigation into virtual lines?
To make it a bit more concrete consider a table of contents rendered as virtual lines. Moving the cursor into them would allow some "jump to heading under cursor" action to be programmed.

@max397574
Copy link
Contributor

the whole point of virtual lines is that they don't rly are there so you can't move the cursor on them I think?

@max397574
Copy link
Contributor

But it would be really nice. Because it would be an easy way to have temporary text.

@dccsillag
Copy link

dccsillag commented Oct 18, 2021

Pretty sure the whole point of virtual lines is to have lines that aren't in the buffer. That means that things such as LSP won't pick up on them, and they can't be accidentaly saved. This is mostly orthogonal to allowing the cursor to be on them.

@mrossinek
Copy link

I absolutely get that! But having some way of moving onto them would be nice. Kinda like gj and gk work on wrapped lines it would be awesome to have some similar function to support moving into virtual lines (they don't need to be mapped to anything by default but having this functionality available for a plugin dev to leverage and map to would be awesome)

@bfredl
Copy link
Member Author

bfredl commented Oct 18, 2021

That sounds more like embedding a sub-buffer into a window (so that the cursor can take positions within the embedded buffer). which might be something we can do, but separate from virtual text/lines as such (which are rather UI elements like statusline/whatevercolumn)

@mrossinek
Copy link

That sounds more like embedding a sub-buffer into a window

Hm interesting 🤔 So do you think like a borderless floating window which gets inserted between lines? That would probably also deal with buffer changes better than the current virtual lines because they get removed after a buffer change. However, if (for example) the ToC were in a yet entirely different buffer that could arguably be handled a bit better..

@vhyrro
Copy link

vhyrro commented Oct 19, 2021

These sorts of attached floating windows sound really cool! They could help out in a lot of scenarios. If the item is treated as an isolated buffer then it gives a lot of freedom to the programmer without having to be worried about messing up the buffer it's contained in :)

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.