fix(picker.input): correct cursor position in input when cycling / focus. Fixes #688

This commit is contained in:
Folke Lemaitre 2025-01-21 18:33:45 +01:00
parent 3fa2ea3115
commit 93cca7a4b3
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 3 additions and 4 deletions

View file

@ -349,13 +349,13 @@ function M.cycle_win(picker)
win = wins[idx % #wins + 1] or 1 -- cycle win = wins[idx % #wins + 1] or 1 -- cycle
vim.api.nvim_set_current_win(win) vim.api.nvim_set_current_win(win)
if win == picker.input.win.win then if win == picker.input.win.win then
vim.cmd("startinsert") vim.cmd("startinsert!")
end end
end end
function M.focus_input(picker) function M.focus_input(picker)
picker.input.win:focus() picker.input.win:focus()
vim.cmd("startinsert") vim.cmd("startinsert!")
end end
function M.focus_list(picker) function M.focus_list(picker)

View file

@ -23,11 +23,10 @@ function M.new(picker)
height = 1, height = 1,
text = picker.opts.live and self.filter.search or self.filter.pattern, text = picker.opts.live and self.filter.search or self.filter.pattern,
ft = "regex", ft = "regex",
vim.cmd.startinsert()
vim.api.nvim_win_set_cursor(self.win.win, { 1, #self:get() + 1 })
on_win = function(win) on_win = function(win)
vim.fn.prompt_setprompt(win.buf, "") vim.fn.prompt_setprompt(win.buf, "")
win:focus() win:focus()
vim.cmd("startinsert!")
end, end,
bo = { bo = {
filetype = "snacks_picker_input", filetype = "snacks_picker_input",