mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 02:38:46 +00:00
fix(picker.actions): when only 1 win, pick_win
will select that automatically. Show warning when no windows. See #623
This commit is contained in:
parent
71070b78f0
commit
ba5a70b84d
2 changed files with 27 additions and 16 deletions
|
@ -132,25 +132,36 @@ function M.pick_win(picker, item, action)
|
|||
local overlays = {} ---@type snacks.win[]
|
||||
picker.layout:hide()
|
||||
local chars = "asdfghjkl"
|
||||
local wins = {} ---@type number[]
|
||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||
if vim.api.nvim_win_get_config(win).relative == "" then
|
||||
local c = chars:sub(1, 1)
|
||||
chars = chars:sub(2)
|
||||
overlays[c] = Snacks.win({
|
||||
backdrop = false,
|
||||
win = win,
|
||||
focusable = false,
|
||||
enter = false,
|
||||
relative = "win",
|
||||
width = 7,
|
||||
height = 3,
|
||||
text = (" \n %s \n "):format(c),
|
||||
wo = {
|
||||
winhighlight = "NormalFloat:SnacksPickerPickWin" .. (win == picker.main and "Current" or ""),
|
||||
},
|
||||
})
|
||||
wins[#wins + 1] = win
|
||||
end
|
||||
end
|
||||
if #wins == 1 then
|
||||
picker.main = wins[1]
|
||||
return
|
||||
elseif #wins == 0 then
|
||||
Snacks.notify.warn("No windows to pick from", { title = "Snacks Picker" })
|
||||
return
|
||||
end
|
||||
for _, win in ipairs(wins) do
|
||||
local c = chars:sub(1, 1)
|
||||
chars = chars:sub(2)
|
||||
overlays[c] = Snacks.win({
|
||||
backdrop = false,
|
||||
win = win,
|
||||
focusable = false,
|
||||
enter = false,
|
||||
relative = "win",
|
||||
width = 7,
|
||||
height = 3,
|
||||
text = (" \n %s \n "):format(c),
|
||||
wo = {
|
||||
winhighlight = "NormalFloat:SnacksPickerPickWin" .. (win == picker.main and "Current" or ""),
|
||||
},
|
||||
})
|
||||
end
|
||||
vim.cmd([[redraw!]])
|
||||
local char = vim.fn.getcharstr()
|
||||
for _, overlay in pairs(overlays) do
|
||||
|
|
|
@ -186,7 +186,7 @@ function State:setup(opts, ctx)
|
|||
if self.all then
|
||||
local picker = self.picker()
|
||||
if not picker then
|
||||
return
|
||||
return {}
|
||||
end
|
||||
picker.list:set_target()
|
||||
self.on_find = function()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue