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

screen*() functions don't register floating windows #19013

Closed
echasnovski opened this issue Jun 18, 2022 · 9 comments · Fixed by #19020
Closed

screen*() functions don't register floating windows #19013

echasnovski opened this issue Jun 18, 2022 · 9 comments · Fixed by #19020
Labels
api libnvim, Nvim RPC API bug issues reporting wrong behavior float floating windows needs:discussion issue needs attention from an expert, or PR proposes significant changes to architecture or API ui ui-extensibility UI extensibility, events, protocol

Comments

@echasnovski
Copy link
Member

Neovim version (nvim -v)

NVIM v0.8.0-dev+441-ge651ae586

Vim (not Nvim) behaves the same?

Yes, with popup windows (8.2.5046)

Operating system/version

EndeavourOS 5.18.3-arch1-1

Terminal name/version

xfce4-terminal 1.0.4 (Xfce 4.16)

$TERM environment variable

xterm-256color

Installation

appimage

How to reproduce the issue

  1. Create 'init-floating.lua' file with following content:
local buf_id = vim.api.nvim_create_buf(true, true)
vim.api.nvim_buf_set_lines(buf_id, 0, -1, true, { 'aaaaaaaaaa' })

vim.api.nvim_open_win(buf_id, false, {
  relative = 'editor',
  width = 10,
  height = 1,
  row = 0,
  col = 0,
})
  1. nvim -u init-floating.lua. Should result in Neovim instance with aaaaaaaaaa in floating window in top left corner.
  2. Run :lua print(vim.inspect(vim.fn.screenstring(1, 1))). It should be "a", but it is " ", which is a character under floating window. The same effect is for screenchar(), screenchars(), and screenattr().

On the other hand, Vim behaves as expected with its popup windows. Use equivalent 'init-popup.vim' file:

call popup_create("aaaaaaaaaa", {"line": 1, "col": 1})

Expected behavior

All screen*() functions respect floating windows, i.e. use them during computation of "what is displayed on the screen".

Actual behavior

neovim-issue_screenstring.mp4
@echasnovski echasnovski added the bug issues reporting wrong behavior label Jun 18, 2022
@zeertzjq zeertzjq added float floating windows needs:discussion issue needs attention from an expert, or PR proposes significant changes to architecture or API labels Jun 18, 2022
@zeertzjq
Copy link
Member

zeertzjq commented Jun 18, 2022

Is this related to your feature request in #19000?

@zeertzjq zeertzjq added the ui label Jun 18, 2022
@echasnovski
Copy link
Member Author

echasnovski commented Jun 18, 2022

Implicitly related, yes. I've built a straightforward get_screenshot() function by traversing all cells (within 1, vim.o.lines x 1, vim.o.columns) with screenstring() and screenattr(). Works like a charm (with couple of design drawbacks), but when testing it, found that it doesn't support floating windows (which is a must for modern plugin testing, unfortunately). As similar works on Vim's side, seems to be an undesirable behavior.

@zeertzjq
Copy link
Member

zeertzjq commented Jun 18, 2022

This may be impossible because AFAIK how floating windows are displayed depends on what UIs are attached.

@clason
Copy link
Member

clason commented Jun 18, 2022

(Remember that Neovim's floating windows are very different from Vim's popups.)

@zeertzjq
Copy link
Member

Although duplicating the code for finding mouse click position may make this work.

@echasnovski
Copy link
Member Author

This may be impossible because AFAIK how floating windows are displayed depends on what UIs are attached.

This is sad.

At least, this means a documentation of these functions are not really up to date. All of them have something like character ... at position [row, col] on the screen.

Although duplicating the code for finding mouse click position may make this work.

And this is better :)
If you, please, could point me to the right direction, I will be trying something. Really want to have the ability to do proper screen tests.

@bfredl
Copy link
Member

bfredl commented Jun 18, 2022

there is also nvim__inspect_cell() which is not standardized yet, but allows you to address floating windows.

@zeertzjq
Copy link
Member

I just noticed this comment:

neovim/src/nvim/eval.c

Lines 6854 to 6857 in cd9e08c

// TODO(bfredl): this is a hack for legacy tests which use screenchar()
// to check printed messages on the screen (but not floats etc
// as these are not legacy features). If the compositor is refactored to
// have its own buffer, this should just read from it instead.

@justinmk justinmk added api libnvim, Nvim RPC API ui-extensibility UI extensibility, events, protocol labels Jun 18, 2022
@echasnovski
Copy link
Member Author

there is also nvim__inspect_cell() which is not standardized yet, but allows you to address floating windows.

I tried incorporating it and did in fact succeed to get data from both main window and floating ones. But not so smartly: by looping grid id from 1 to 100 and seeing if there is a valid output. As I couldn't find a way to match window id to a grid id with exported Lua API (if this even makes sense). It also seem to lead to other hassles: manually computing which floating window is on top through z-index, aligning grids (as coordinates seem to be "per window"), dealing with occasional segfaults... Not as straightforward as I hoped with screenstring() and screenattr() :(

echasnovski added a commit to echasnovski/neovim that referenced this issue Jun 19, 2022
echasnovski added a commit to echasnovski/neovim that referenced this issue Jun 19, 2022
echasnovski added a commit to echasnovski/neovim that referenced this issue Jun 19, 2022
echasnovski added a commit to echasnovski/neovim that referenced this issue Jun 23, 2022
kraftwerk28 pushed a commit to kraftwerk28/neovim that referenced this issue Jul 6, 2022
smjonas pushed a commit to smjonas/neovim that referenced this issue Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api libnvim, Nvim RPC API bug issues reporting wrong behavior float floating windows needs:discussion issue needs attention from an expert, or PR proposes significant changes to architecture or API ui ui-extensibility UI extensibility, events, protocol
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants