feat(picker): opts.focus = "input"|"list"|false to configure what to focus (if anything) when showing the picker

This commit is contained in:
Folke Lemaitre 2025-01-30 10:39:03 +01:00
parent 7f0cde31c4
commit 5a8d79847b
2 changed files with 7 additions and 1 deletions

View file

@ -83,6 +83,7 @@ local M = {}
---@field prompt? string prompt text / icon
---@field title? string defaults to a capitalized source name
---@field auto_close? boolean automatically close the picker when focusing another window (defaults to true)
---@field focus? "input"|"list"|false where to focus when the picker is opened (defaults to "input")
--- Preset options
---@field previewers? snacks.picker.previewers.Config|{}
---@field formatters? snacks.picker.formatters.Config|{}
@ -101,6 +102,7 @@ local M = {}
local defaults = {
prompt = "",
sources = {},
focus = "input",
layout = {
cycle = true,
--- Use the default layout or vertical if the window is too narrow

View file

@ -436,7 +436,11 @@ function M:show()
if self.preview.main then
self.preview.win:show()
end
self.input.win:focus()
if self.opts.focus == "input" then
self.input.win:focus()
elseif self.opts.focus == "list" then
self.list.win:focus()
end
if self.opts.on_show then
self.opts.on_show(self)
end