fix(previewer): preview message out of bounds (#3003)
* 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.
This commit is contained in:
@@ -188,11 +188,20 @@ utils.set_preview_message = function(bufnr, winid, message, fillchar)
|
|||||||
)
|
)
|
||||||
local anon_ns = vim.api.nvim_create_namespace ""
|
local anon_ns = vim.api.nvim_create_namespace ""
|
||||||
local padding = table.concat(ts_utils.repeated_table(#message + 4, " "), "")
|
local padding = table.concat(ts_utils.repeated_table(#message + 4, " "), "")
|
||||||
local lines = {
|
local formatted_message = " " .. message .. " "
|
||||||
padding,
|
-- Populate lines table based on height
|
||||||
" " .. message .. " ",
|
local lines = {}
|
||||||
padding,
|
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(
|
vim.api.nvim_buf_set_extmark(
|
||||||
bufnr,
|
bufnr,
|
||||||
anon_ns,
|
anon_ns,
|
||||||
@@ -200,12 +209,13 @@ utils.set_preview_message = function(bufnr, winid, message, fillchar)
|
|||||||
0,
|
0,
|
||||||
{ end_line = height, hl_group = "TelescopePreviewMessageFillchar" }
|
{ 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
|
for i, line in ipairs(lines) do
|
||||||
|
local line_pos = math.floor(height / 2) - 2 + i
|
||||||
vim.api.nvim_buf_set_extmark(
|
vim.api.nvim_buf_set_extmark(
|
||||||
bufnr,
|
bufnr,
|
||||||
anon_ns,
|
anon_ns,
|
||||||
math.floor(height / 2) - 1 + i,
|
math.max(line_pos, 0),
|
||||||
0,
|
0,
|
||||||
{ virt_text = { { line, "TelescopePreviewMessage" } }, virt_text_pos = "overlay", virt_text_win_col = col }
|
{ virt_text = { { line, "TelescopePreviewMessage" } }, virt_text_pos = "overlay", virt_text_win_col = col }
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user