mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 02:38:46 +00:00
fix(picker): properly handle opts.layout
being a string. Fixes #636
This commit is contained in:
parent
197d063519
commit
b80c9d275d
2 changed files with 5 additions and 4 deletions
|
@ -32,7 +32,7 @@ end
|
|||
---@param picker snacks.Picker
|
||||
function M.new(picker)
|
||||
local self = setmetatable({}, M)
|
||||
self.reverse = picker.opts.layout.reverse
|
||||
self.reverse = picker.resolved_layout.reverse
|
||||
self.picker = picker
|
||||
self.selected = {}
|
||||
self.selected_map = {}
|
||||
|
@ -180,7 +180,7 @@ function M:_move(to, absolute, render)
|
|||
self.cursor, self.top = 1, 1
|
||||
else
|
||||
self.cursor = absolute and to or self.cursor + to
|
||||
if self.picker.opts.layout.cycle then
|
||||
if self.picker.resolved_layout.cycle then
|
||||
self.cursor = (self.cursor - 1) % self:count() + 1
|
||||
end
|
||||
self.cursor = minmax(self.cursor, 1, self:count())
|
||||
|
|
|
@ -88,6 +88,7 @@ function M.new(opts)
|
|||
M._active[self] = true
|
||||
|
||||
local layout = Snacks.picker.config.layout(self.opts)
|
||||
self.resolved_layout = layout
|
||||
self.list = require("snacks.picker.core.list").new(self)
|
||||
self.input = require("snacks.picker.core.input").new(self)
|
||||
self.preview = require("snacks.picker.core.preview").new(self.opts, layout.preview == "main" and self.main or nil)
|
||||
|
@ -137,7 +138,7 @@ end
|
|||
function M:init_layout(layout)
|
||||
layout = layout or Snacks.picker.config.layout(self.opts)
|
||||
self.resolved_layout = vim.deepcopy(layout)
|
||||
self.resolved_layout.cycle = nil -- not needed for applying layout
|
||||
self.resolved_layout.cycle = self.resolved_layout.cycle == true
|
||||
local opts = layout --[[@as snacks.layout.Config]]
|
||||
local preview_main = layout.preview == "main"
|
||||
local preview_hidden = layout.preview == false or preview_main
|
||||
|
@ -182,7 +183,7 @@ function M:set_layout(layout)
|
|||
layout = layout or Snacks.picker.config.layout(self.opts)
|
||||
layout = type(layout) == "string" and Snacks.picker.config.layout(layout) or layout
|
||||
---@cast layout snacks.picker.layout.Config
|
||||
layout.cycle = nil -- not needed for applying layout
|
||||
layout.cycle = layout.cycle == true
|
||||
if vim.deep_equal(layout, self.resolved_layout) then
|
||||
-- no need to update
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue