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: layout relative to current cursor position #496

Closed
Luxed opened this issue Feb 4, 2021 · 2 comments · Fixed by #878
Closed

feat: layout relative to current cursor position #496

Luxed opened this issue Feb 4, 2021 · 2 comments · Fixed by #878
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@Luxed
Copy link
Contributor

Luxed commented Feb 4, 2021

Why?
When using things like LSP related pickers, I don't usually want them to take all of the space on my screen, especially things like the lsp_code_actions picker would be a lot better to use if it was smaller and relative to my cursor's position.

How would I see it implemented?
I actually already started trying to implement it. Here's the layout I had in mind:

+--------------+---------------------+
|    Prompt    |      Previewer      |
+--------------+      Previewer      |
|    Result    |      Previewer      |
|    Result    |      Previewer      |
+--------------+---------------------+

With the top left being the cursor's position. The previewer would be optional, but I put it here because that's how the Visual Studio IDE displays it on code actions.

What knowledge I'm missing to make it work
As said above, I already have a branch that has the basic idea, my issue is with getting the current cursor position.
I've gone through the help and found a bunch of things like nvim_win_get_position, nvim_win_get_cursor, getline, wincol, screencol, etc.
But nothing actually allows me to get the position of the cursor on screen without counting the folds, the fact that the buffer can be scrolled, splits, tabline, sign column, line number column, etc.
If someone knows what functions to get the position or knows what functions to use and calculate the cursor position, then I'd be able to do it myself.
Another thing that I would need to know is the size of the current neovim instance, so that if the coordinates are out of bound, I can position everything at the right place. I think these are given by the lines and columns options from what I understand.

@Luxed Luxed added the enhancement Enhancement to performance, inner workings or existent features label Feb 4, 2021
@rockerBOO
Copy link
Member

To make new layouts, check out https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/pickers/layout_strategies.lua for how it is currently being done. To make the layout relative to the cursor position should be possible since we can access the current cursor state inside the strategy.

I will let others comment on getting the cursor position.

@Luxed
Copy link
Contributor Author

Luxed commented Feb 5, 2021

Thank you for answering @rockerBOO.

I've ended up playing around with it a little bit more. I was able to get something that gets the current cursor position by using a combination of nvim_win_get_position(0), winline() and wincol().
Here's a little preview of how I want it to look (without the "preview" float for now and with a custom theme):
image
In the screenshot, my cursor is on the : character on the line saying "Special keys:".

I'll be able to proceed with what I have right now since it works for all of the cases I have tested for myself. Once I'm happy with it, I'll create a PR ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants