mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(picker.preview): better positioning of preview location
Some checks failed
CI / ci (push) Failing after 0s
Some checks failed
CI / ci (push) Failing after 0s
This commit is contained in:
parent
b1f415e3c3
commit
38649556ee
1 changed files with 8 additions and 3 deletions
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue