feat(picker.preview): better positioning of preview location
Some checks failed
CI / ci (push) Failing after 0s

This commit is contained in:
Folke Lemaitre 2025-01-23 21:30:43 +01:00
parent b1f415e3c3
commit 38649556ee
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -222,12 +222,16 @@ function M:loc()
local line_count = vim.api.nvim_buf_line_count(self.win.buf)
Snacks.picker.util.resolve_loc(self.item, self.win.buf)
if self.item.pos and self.item.pos[1] > 0 and self.item.pos[1] <= line_count then
vim.api.nvim_win_set_cursor(self.win.win, { self.item.pos[1], 0 })
local function show(pos)
vim.api.nvim_win_set_cursor(self.win.win, pos)
vim.api.nvim_win_call(self.win.win, function()
vim.cmd("norm! zz")
vim.cmd("norm! zzze")
self:wo({ cursorline = true })
end)
end
if self.item.pos and self.item.pos[1] > 0 and self.item.pos[1] <= line_count then
show(self.item.pos)
if self.item.end_pos then
vim.api.nvim_buf_set_extmark(self.win.buf, ns_loc, self.item.pos[1] - 1, self.item.pos[2], {
end_row = self.item.end_pos[1] - 1,
@ -240,6 +244,7 @@ function M:loc()
local start = self.item.pos[2]
local from, to = re:match_line(self.win.buf, self.item.pos[1] - 1, start)
if from and to then
show({ self.item.pos[1], start + to }) -- make sure the to column is visible
vim.api.nvim_buf_set_extmark(self.win.buf, ns_loc, self.item.pos[1] - 1, start + from, {
end_col = start + to,
hl_group = "SnacksPickerSearch",