which-key.nvim icon indicating copy to clipboard operation
which-key.nvim copied to clipboard

[Feature Request] Smart window position

Open utilyre opened this issue 2 years ago • 1 comments

It'd be cool if we had a smart window positioning kind of thing which would show the popup menu on top if the cursor is on the bottom split of the screen and vise versa.

There has been many times that I was editing a file with my cursor on the bottom of screen and I pressed leader key to do something which brought up the popup menu on the line I was editing.

Thanks for the fantastic plugin

utilyre avatar May 09 '22 13:05 utilyre

Same request as you (Sadly that the issue is still opened after one year 😂).

I've tried to pass a function to window.position param in setup{} but it seems to only accept string type.

-- lua/plugins/whichkey.lua
require('whichkey').setup{
	window = {
		border = "none", -- none, single, double, shadow
		position = function() -- dynamic position
			return require("core.utils").curor_lower_win() and "top" or "bottom"
		end, -- bottom, top
       }
}
-- lua/core/utils.lua
curor_lower_win = function()
	local top = vim.fn.line("w0", 0)
	local h = vim.api.nvim_win_get_height(0)
	local cur = vim.api.nvim_win_get_cursor(0)
	return (cur[1] - top) > (h / 2)
end

Expecting for any hook to controll this measure.

WilliamBy avatar Sep 09 '23 09:09 WilliamBy