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

fix(menu): allow relative win settings other than win #90

Merged
merged 2 commits into from
Sep 26, 2023

Conversation

willothy
Copy link
Collaborator

Allows menus to be created with positions relative to cursor, editor, etc.

Main reason for this is that I'm working on a dropbar_menu_t implementation of vim.ui.select.

@willothy willothy changed the title fix(menu): ensure win key is nil if win_configs.relative ~= "win" fix(menu): allow relative win settings other than win Sep 25, 2023
@Bekaboo
Copy link
Owner

Bekaboo commented Sep 25, 2023

@willothy Is there any problem if we left win field untouched when win_configs.relative ~= 'win'?

@willothy
Copy link
Collaborator Author

willothy commented Sep 25, 2023

Yes if relative ~= "win" and the win field is set then nvim throws a validation error.

Added a few more changes to this as well, needed for positioning of the fzf window (also hides the fzf top border if possible to save height).

@willothy
Copy link
Collaborator Author

willothy commented Sep 25, 2023

Also, the ui-select is working great, just needs a bit more work on positioning. Here's a demo:

I've also added custom extmarks to the 3rd section of the demo, to showcase an idea I've had where menu entries could have virtual text displayed below them for extra line-associated context.

  1. Code actions ui-select
  2. :OverseerRun
  3. overseer.nvim task actions, with custom extmarks

The menu class is very versatile and feels better than telescope or nui for this kind of thing because you get the power of the fuzzy finder, but also the hjkl navigation and motions of a nui menu.

2023-09-25.03-23-35.mp4

Ensures `win` key is nil if `win_configs.relative` ~= `"win"`,
and sets the fzf window location relative to the main window instead
of calculating the `relative="editor"` width.
@Bekaboo
Copy link
Owner

Bekaboo commented Sep 26, 2023

@willothy

Yes if relative ~= "win" and the win field is set then nvim throws a validation error.

I then wonder why win field is set if relative field is not "win". It would be better if we can avoid calling nvim_open_win() with wrong _win_configs at the beginning rather than fixing the parameterss just before calling the ``nvim_open_win()` function.

@willothy
Copy link
Collaborator Author

willothy commented Sep 26, 2023

It's set because the global configs are used when creating windows, and overridden by the menu-local settings, but vim.tbl_deep_extend will not replace non-nil with nil so if the default win config uses relative = "win" (which it does), win will be set even if the menu-local win config doesn't set it.

I'm not sure how that could be done other than completely overriding the global config with window-local settings, which I don't think would be ideal.

Checking the win key manually might not be a very pretty fix, but it is the simplest one I could come up with.

@Bekaboo
Copy link
Owner

Bekaboo commented Sep 26, 2023

@willothy This makes full sense to me, thanks for pointing out. Could we fix the wrong _win_configs field in method dropbar_menu_t:eval_win_configs()?

@willothy
Copy link
Collaborator Author

@willothy This makes full sense to me, thanks for pointing out. Could we fix the wrong _win_configs field in method dropbar_menu_t:eval_win_configs()?

Yes, definitely. Updated!

@Bekaboo Bekaboo merged commit 2d383f4 into Bekaboo:master Sep 26, 2023
4 checks passed
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.

2 participants