mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 02:38:46 +00:00
feat(picker): on_show
+ impl for lines
to show with current cursor
This commit is contained in:
parent
e390b7d874
commit
9a7020fd18
3 changed files with 12 additions and 0 deletions
|
@ -75,7 +75,9 @@ local M = {}
|
|||
---@field icons? snacks.picker.icons
|
||||
---@field source? string
|
||||
---@field on_change? fun(picker:snacks.Picker, item:snacks.picker.Item) called when the cursor changes
|
||||
---@field on_show? fun(picker:snacks.Picker) called when the picker is shown
|
||||
---@field layouts? table<string, snacks.picker.Layout>
|
||||
---@field main? snacks.picker.main.Config
|
||||
local defaults = {
|
||||
prompt = " ",
|
||||
sources = {},
|
||||
|
|
|
@ -266,6 +266,13 @@ M.lines = {
|
|||
preview = "main",
|
||||
preset = "ivy",
|
||||
},
|
||||
---@param picker snacks.Picker
|
||||
on_show = function(picker)
|
||||
local cursor = vim.api.nvim_win_get_cursor(picker.main)
|
||||
local info = vim.api.nvim_win_call(picker.main, vim.fn.winsaveview)
|
||||
picker.list:view(cursor[1], info.topline)
|
||||
picker:show_preview()
|
||||
end,
|
||||
}
|
||||
|
||||
-- Loclist
|
||||
|
|
|
@ -263,6 +263,9 @@ function M:show()
|
|||
self.preview.win:show()
|
||||
end
|
||||
self.input.win:focus()
|
||||
if self.opts.on_show then
|
||||
self.opts.on_show(self)
|
||||
end
|
||||
end
|
||||
|
||||
---@return fun():snacks.picker.Item?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue