fix(picker): don't jump to invalid positions. Fixes #712

This commit is contained in:
Folke Lemaitre 2025-01-23 12:43:33 +01:00
parent f57350f1d1
commit 51adb6792e
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 2 additions and 2 deletions

View file

@ -77,7 +77,7 @@ function M.jump(picker, _, action)
vim.api.nvim_win_set_buf(win, buf) vim.api.nvim_win_set_buf(win, buf)
-- set the cursor -- set the cursor
if item.pos then if item.pos and item.pos[1] > 0 then
vim.api.nvim_win_set_cursor(win, { item.pos[1], item.pos[2] }) vim.api.nvim_win_set_cursor(win, { item.pos[1], item.pos[2] })
elseif item.search then elseif item.search then
vim.cmd(item.search) vim.cmd(item.search)

View file

@ -54,7 +54,7 @@ function M.filename(item, picker)
else else
ret[#ret + 1] = { path, "SnacksPickerFile", field = "file" } ret[#ret + 1] = { path, "SnacksPickerFile", field = "file" }
end end
if item.pos then if item.pos and item.pos[1] > 0 then
ret[#ret + 1] = { ":", "SnacksPickerDelim" } ret[#ret + 1] = { ":", "SnacksPickerDelim" }
ret[#ret + 1] = { tostring(item.pos[1]), "SnacksPickerRow" } ret[#ret + 1] = { tostring(item.pos[1]), "SnacksPickerRow" }
if item.pos[2] > 0 then if item.pos[2] > 0 then