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

screenpos() returns wrong result for some windows / tabs. #19606

Closed
pbogut opened this issue Aug 1, 2022 · 8 comments
Closed

screenpos() returns wrong result for some windows / tabs. #19606

pbogut opened this issue Aug 1, 2022 · 8 comments
Labels
bug issues reporting wrong behavior needs:repro We need minimal steps to reproduce the issue ui
Milestone

Comments

@pbogut
Copy link
Sponsor

pbogut commented Aug 1, 2022

Neovim version (nvim -v)

NVIM v0.8.0-dev-nightly-2-gd529523027

Vim (not Nvim) behaves the same?

Not sure, it happens randomly and I notice it only when using nvim-cmp

Operating system/version

Linux / Arch Linux

Terminal name/version

alacritty 0.10.1

$TERM environment variable

xterm-256color

Installation

AUR / neovim-git

How to reproduce the issue

Happens randomly, was not able to reproduce it on demand yet, if I figure this out I will update isuue.

Expected behavior

screenpos() to always return correct position.

Actual behavior

When using screenpos() sometimes result is wrong:

{
  col = 0,
  curscol = 0,
  endcol = 0,
  row = 1
}

I've created a helper binding to test it:

:nmap <c-s> :lua print(vim.inspect(vim.fn.screenpos(0, vim.api.nvim_win_get_cursor(0)[1], vim.api.nvim_win_get_cursor(0)[2]+1)))<cr>

When I use <c-s> it sometimes returns this wrong data set. When it gets broken, it is broken for every window in given tab, if I open split, change buffer it is all broken. Same file in different tab will work all right.

I've also noticed that when I use :set nowrap it gets fixed and works with no issues (even when follow with :set wrap it still works till it gets broken again).

By default I have wrap enabled.

This affects nvim-cmp for me. When function doesn't work the completion window is rendered in left top corner no matter what my position in the window is.

In example below on both tabs I'm on the line 10 and using my helper mapping <c-s>:

Correct result:
screenshot_from_2022-08-01_11-46-25

Wrong result:
screenshot_from_2022-08-01_11-46-34

@pbogut pbogut added the bug issues reporting wrong behavior label Aug 1, 2022
@justinmk
Copy link
Member

justinmk commented Aug 1, 2022

related: #19020 @echasnovski may have insight.

@justinmk justinmk added this to the backlog milestone Aug 1, 2022
@justinmk justinmk added the ui label Aug 1, 2022
@echasnovski
Copy link
Member

My guess is that it has something to do with legacy screenchar() tests that are used to check command line output. It might be the "correct" result for message area. Maybe it is happening for when some messages are shown or Command mode is active?
Does using <Cmd> in mapping changes observations? So like this:

:nmap <c-s> <Cmd>lua print(vim.inspect(vim.fn.screenpos(0, vim.api.nvim_win_get_cursor(0)[1], vim.api.nvim_win_get_cursor(0)[2]+1)))<cr>

@pbogut
Copy link
Sponsor Author

pbogut commented Aug 1, 2022

As far as I can tell there is no difference if i use :lua .... or <cmd>lua .... Results are the same.

Also, another thing that is affected when bug happens is Telescope, I have shifted list when error is in place:

When all is all right:
screenshot_from_2022-08-01_15-53-49

When bug occurs:
screenshot_from_2022-08-01_15-53-40

I've also noticed that updating wrap in window helps even if its not changed:
:lua vim.wo.wrap = vim.wo.wrap maks this bug go away (for some time).

@echasnovski
Copy link
Member

@justinmk, other than that, I don't think these issues are related. screenpos() has different implementation than screenattr(), screenchar(), screenchars(), and screenstring(). It uses textpos2screenpos() which indeed has something to do with wrap. Maybe problem is there.

@pbogut
Copy link
Sponsor Author

pbogut commented Aug 26, 2022

If it's any help at all I noticed it is only happening when I'm using vertical splits. Never happens without split being created first.

@johnwilmes

This comment was marked as off-topic.

@zeertzjq

This comment was marked as off-topic.

@zeertzjq zeertzjq added the needs:repro We need minimal steps to reproduce the issue label Jan 27, 2023
@zeertzjq
Copy link
Member

Closing because nothing can be done without steps to reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior needs:repro We need minimal steps to reproduce the issue ui
Projects
None yet
Development

No branches or pull requests

5 participants