mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-11 14:18:14 +00:00
feat(picker): opts.focus = "input"|"list"|false
to configure what to focus (if anything) when showing the picker
This commit is contained in:
parent
7f0cde31c4
commit
5a8d79847b
2 changed files with 7 additions and 1 deletions
|
@ -83,6 +83,7 @@ local M = {}
|
||||||
---@field prompt? string prompt text / icon
|
---@field prompt? string prompt text / icon
|
||||||
---@field title? string defaults to a capitalized source name
|
---@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 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
|
--- Preset options
|
||||||
---@field previewers? snacks.picker.previewers.Config|{}
|
---@field previewers? snacks.picker.previewers.Config|{}
|
||||||
---@field formatters? snacks.picker.formatters.Config|{}
|
---@field formatters? snacks.picker.formatters.Config|{}
|
||||||
|
@ -101,6 +102,7 @@ local M = {}
|
||||||
local defaults = {
|
local defaults = {
|
||||||
prompt = " ",
|
prompt = " ",
|
||||||
sources = {},
|
sources = {},
|
||||||
|
focus = "input",
|
||||||
layout = {
|
layout = {
|
||||||
cycle = true,
|
cycle = true,
|
||||||
--- Use the default layout or vertical if the window is too narrow
|
--- Use the default layout or vertical if the window is too narrow
|
||||||
|
|
|
@ -436,7 +436,11 @@ function M:show()
|
||||||
if self.preview.main then
|
if self.preview.main then
|
||||||
self.preview.win:show()
|
self.preview.win:show()
|
||||||
end
|
end
|
||||||
|
if self.opts.focus == "input" then
|
||||||
self.input.win:focus()
|
self.input.win:focus()
|
||||||
|
elseif self.opts.focus == "list" then
|
||||||
|
self.list.win:focus()
|
||||||
|
end
|
||||||
if self.opts.on_show then
|
if self.opts.on_show then
|
||||||
self.opts.on_show(self)
|
self.opts.on_show(self)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue