fix: which key float positioning (#1293)

* Adjust which key float positioning for recent plenary and telescope theme changes
This commit is contained in:
fdschmidt93
2021-09-30 15:53:06 +02:00
committed by GitHub
parent 4e629cdea1
commit 440c598de4

View File

@@ -1026,10 +1026,16 @@ actions.which_key = function(prompt_bufnr, opts)
local winheight = opts.num_rows + 2 * opts.line_padding local winheight = opts.num_rows + 2 * opts.line_padding
-- place hints at top or bottom relative to prompt -- place hints at top or bottom relative to prompt
local win_central_row = function(win_nr)
return a.nvim_win_get_position(win_nr)[1] + 0.5 * a.nvim_win_get_height(win_nr)
end
-- TODO(fdschmidt93|l-kershaw): better generalization of where to put which key float
local picker = action_state.get_current_picker(prompt_bufnr) local picker = action_state.get_current_picker(prompt_bufnr)
local prompt_win = picker.prompt_win local prompt_row = win_central_row(picker.prompt_win)
local prompt_row = a.nvim_win_get_position(prompt_win)[1] local results_row = win_central_row(picker.results_win)
local prompt_pos = prompt_row <= 0.5 * vim.o.lines local preview_row = win_central_row(picker.preview_win)
local prompt_pos = prompt_row < 0.4 * vim.o.lines
or prompt_row < 0.6 * vim.o.lines and results_row + preview_row < vim.o.lines
local modes = { n = "Normal", i = "Insert" } local modes = { n = "Normal", i = "Insert" }
local title_mode = opts.only_show_current_mode and modes[mode] .. " Mode " or "" local title_mode = opts.only_show_current_mode and modes[mode] .. " Mode " or ""
@@ -1041,8 +1047,8 @@ actions.which_key = function(prompt_bufnr, opts)
maxwidth = vim.o.columns, maxwidth = vim.o.columns,
minheight = winheight, minheight = winheight,
maxheight = winheight, maxheight = winheight,
line = prompt_pos == true and vim.o.lines - winheight or 0, line = prompt_pos == true and vim.o.lines - winheight + 1 or 1,
col = 1, col = 0,
border = { prompt_pos and 1 or 0, 0, not prompt_pos and 1 or 0, 0 }, border = { prompt_pos and 1 or 0, 0, not prompt_pos and 1 or 0, 0 },
borderchars = { prompt_pos and "" or " ", "", not prompt_pos and "" or " ", "", "", "", "", "" }, borderchars = { prompt_pos and "" or " ", "", not prompt_pos and "" or " ", "", "", "", "", "" },
noautocmd = true, noautocmd = true,