Fix resize/preview toggles of the cursor layout (#2718)

The cursor layout uses winline() and wincol() to calculate the cursor
position. Both these functions operate on the currently active window.
The first time the calculations are performed, that happens to be the
window active before showing the Telescope window. However, if the
editor is then resized or the preview window is toggled, the active
window changes. The result is that recalculating the position is then
done using the wrong window, resulting in the Telescope window moving
around in an erratic manner.

To fix this, we have to scope the winline() and wincol() calls to the
original window ID.
This commit is contained in:
Yorick Peterse
2023-09-27 04:41:34 +02:00
committed by GitHub
parent ed9574dd6d
commit 5c91b855b8

View File

@@ -565,6 +565,7 @@ layout_strategies.cursor = make_documented_layout(
local preview = initial_options.preview local preview = initial_options.preview
local results = initial_options.results local results = initial_options.results
local prompt = initial_options.prompt local prompt = initial_options.prompt
local winid = self.original_win_id
local height_opt = layout_config.height local height_opt = layout_config.height
local height = resolve.resolve_height(height_opt)(self, max_columns, max_lines) local height = resolve.resolve_height(height_opt)(self, max_columns, max_lines)
@@ -599,16 +600,16 @@ layout_strategies.cursor = make_documented_layout(
results.width = prompt.width results.width = prompt.width
end end
local position = vim.api.nvim_win_get_position(0) local position = vim.api.nvim_win_get_position(winid)
local winbar = (function() local winbar = (function()
if vim.fn.exists "&winbar" == 1 then if vim.fn.exists "&winbar" == 1 then
return vim.o.winbar == "" and 0 or 1 return vim.wo[winid].winbar == "" and 0 or 1
end end
return 0 return 0
end)() end)()
local top_left = { local top_left = {
line = vim.fn.winline() + position[1] + bs + winbar, line = vim.api.nvim_win_call(winid, vim.fn.winline) + position[1] + bs + winbar,
col = vim.fn.wincol() + position[2], col = vim.api.nvim_win_call(winid, vim.fn.wincol) + position[2],
} }
local bot_right = { local bot_right = {
line = top_left.line + height - 1, line = top_left.line + height - 1,