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

nvim_open_win cursor-relative position depends on buffer text #21752

Closed
anuvyklack opened this issue Jan 11, 2023 · 8 comments
Closed

nvim_open_win cursor-relative position depends on buffer text #21752

anuvyklack opened this issue Jan 11, 2023 · 8 comments
Labels
closed:invalid Issues that are closed as "invalid"

Comments

@anuvyklack
Copy link

anuvyklack commented Jan 11, 2023

Describe the bug

Today I updated to Neovim v0.8.2 and my fold-preveiw plugin stopped working as it should. I haven't updated the plugin since November.

The plugin should open float window with folded region preview indented the same way the folded code is. But now all float windows are opened in the zero column. I am not the only one who faced this issue.

The plugin is quite simple and contains only one file. The code point that open a window.

I made some research and found that the nvim_open_win api function is broken.

I open Neovim with nvim --clean and execute next command in different places of the buffer

:lua vim.api.nvim_open_win(0, false, { 
    anchor = 'NW',
    border = 'rounded',
    relative = 'win',
    bufpos = vim.api.nvim_win_get_cursor(0),
    width = 25,
    height = 10
})

The command should open the float window under the cursor. If there is a text in the place when float window should appear, then its position would be correct:

Screenshot from 2023-01-11 17-36-45
Screenshot from 2023-01-11 17-39-57

But if there is no text, then float window sticks to the last letter.
Look at the cursor position and at the float window position.

Screenshot from 2023-01-11 17-41-04
Screenshot from 2023-01-11 17-41-48

Steps to reproduce

nvim --clean file.txt

Execute next command at the end of the most long line, so that all below lines are shorter,

:lua vim.api.nvim_open_win(0, false, { anchor = 'NW', border = 'rounded', relative = 'win', bufpos = vim.api.nvim_win_get_cursor(0), width = 25, height = 10 })

Expected behavior

The floating window should open such that it left upper corner should appear one line under the cursor position.

Neovim version (nvim -v)

0.8.2

Vim (not Nvim) behaves the same?

Operating system/version

fedora 36

Terminal name/version

kitty 0.26.5

$TERM environment variable

tmux-256color

Installation

dnf

@anuvyklack anuvyklack added the bug issues reporting wrong behavior label Jan 11, 2023
@anuvyklack anuvyklack changed the title nvim_open_win api, with relative = "win" is broken! 0.8.2 broke nvim_open_win api, with relative = "win"! Jan 11, 2023
@justinmk
Copy link
Member

Today I updated to Neovim v0.8.2

is this a regression compared to 0.8.1, i.e. did it work for you in 0.8.1 (else please say which version worked for you)?

If there is a text in the place when float window should appear, then its position would be correct:

so it looks like the issue depends on presence of text in the buffer.

"nvim_open_win is broken!" is a bit much, in the future please choose a more precise issue title.

@justinmk justinmk changed the title 0.8.2 broke nvim_open_win api, with relative = "win"! nvim_open_win cursor-relative position depends on buffer text Jan 11, 2023
@justinmk justinmk added the float floating windows label Jan 11, 2023
@justinmk justinmk modified the milestones: backlog, 0.8.3 Jan 11, 2023
@justinmk justinmk added the bug-regression wrong behavior that was introduced in a previous commit (please bisect) label Jan 11, 2023
@zeertzjq zeertzjq assigned zeertzjq and unassigned zeertzjq Jan 11, 2023
@zeertzjq
Copy link
Member

zeertzjq commented Jan 11, 2023

You need to subtract by one when passing line number returned by nvim_win_get_cursor. That it worked as expected for you previously is a bug.

@zeertzjq zeertzjq closed this as not planned Won't fix, can't repro, duplicate, stale Jan 11, 2023
@zeertzjq zeertzjq added closed:invalid Issues that are closed as "invalid" and removed bug issues reporting wrong behavior bug-regression wrong behavior that was introduced in a previous commit (please bisect) float floating windows labels Jan 11, 2023
@zeertzjq zeertzjq removed this from the 0.8.3 milestone Jan 11, 2023
@anuvyklack
Copy link
Author

anuvyklack commented Jan 11, 2023

No. The problem is not the line position. And I subtracted one, so this behavior was correct.

The problem is column position.

@anuvyklack
Copy link
Author

anuvyklack commented Jan 11, 2023

@zeertzjq, you get it wrong, the issue is still here!

@clason
Copy link
Member

clason commented Jan 11, 2023

Well, I'd argue that you were first to get the minimal reproducing example wrong. First step would be to correct that.

To be clear, the behavior you showed here (code + screenshots) is the expected behavior and not an error.

@zeertzjq
Copy link
Member

If the anchored buffer text position is in a fold than the previous behavior makes even less sense.

@anuvyklack
Copy link
Author

Ok, maybe you're right, and there was a bug that I relied on.

@anuvyklack
Copy link
Author

Anchored buffer text position was not inside fold, but first line of the fold, which is available, as I understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:invalid Issues that are closed as "invalid"
Projects
None yet
Development

No branches or pull requests

4 participants