Skip to content

Commit

Permalink
fix(previewer): preview message out of bounds (#3003)
Browse files Browse the repository at this point in the history
* fix(set_preview_message): check line height of previewer before setting message.

* style: run changed file through stylua and remove unused variable.

* refactor: change lines table instead. check max between line_pos and 0

* style: run changed file through stylua.

(cherry picked from commit c2b8311)
  • Loading branch information
TanglingTreats authored and Conni2461 committed May 20, 2024
1 parent d7d32a3 commit 097a64a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lua/telescope/previewers/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,34 @@ utils.set_preview_message = function(bufnr, winid, message, fillchar)
)
local anon_ns = vim.api.nvim_create_namespace ""
local padding = table.concat(ts_utils.repeated_table(#message + 4, " "), "")
local lines = {
padding,
" " .. message .. " ",
padding,
}
local formatted_message = " " .. message .. " "
-- Populate lines table based on height
local lines = {}
if height == 1 then
lines[1] = formatted_message
else
for i = 1, math.min(height, 3), 1 do
if i % 2 == 0 then
lines[i] = formatted_message
else
lines[i] = padding
end
end
end
vim.api.nvim_buf_set_extmark(
bufnr,
anon_ns,
0,
0,
{ end_line = height, hl_group = "TelescopePreviewMessageFillchar" }
)
local col = math.floor((width - strings.strdisplaywidth(lines[2])) / 2)
local col = math.floor((width - strings.strdisplaywidth(formatted_message)) / 2)
for i, line in ipairs(lines) do
local line_pos = math.floor(height / 2) - 2 + i
vim.api.nvim_buf_set_extmark(
bufnr,
anon_ns,
math.floor(height / 2) - 1 + i,
math.max(line_pos, 0),
0,
{ virt_text = { { line, "TelescopePreviewMessage" } }, virt_text_pos = "overlay", virt_text_win_col = col }
)
Expand Down

0 comments on commit 097a64a

Please sign in to comment.