mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(picker): allow setting a custom opts.title
. Fixes #620
This commit is contained in:
parent
cd58a14e20
commit
6001fb2077
4 changed files with 12 additions and 10 deletions
|
@ -291,7 +291,7 @@ end
|
|||
|
||||
function M.toggle_live(picker)
|
||||
if not picker.opts.supports_live then
|
||||
Snacks.notify.warn("Live search is not supported for `" .. picker.source_name .. "`", { title = "Snacks Picker" })
|
||||
Snacks.notify.warn("Live search is not supported for `" .. picker.title .. "`", { title = "Snacks Picker" })
|
||||
return
|
||||
end
|
||||
picker.opts.live = not picker.opts.live
|
||||
|
|
|
@ -72,6 +72,7 @@ local M = {}
|
|||
---@field layout? snacks.picker.layout.Config|string|{}|fun(source:string):(snacks.picker.layout.Config|string)
|
||||
---@field icons? snacks.picker.icons
|
||||
---@field prompt? string prompt text / icon
|
||||
---@field title? string defaults to a capitalized source name
|
||||
--- Preset options
|
||||
---@field previewers? snacks.picker.previewers.Config|{}
|
||||
---@field formatters? snacks.picker.formatters.Config|{}
|
||||
|
|
|
@ -11,7 +11,7 @@ M.default = {
|
|||
{
|
||||
box = "vertical",
|
||||
border = "rounded",
|
||||
title = "{source} {live} {flags}",
|
||||
title = "{title} {live} {flags}",
|
||||
{ win = "input", height = 1, border = "bottom" },
|
||||
{ win = "list", border = "none" },
|
||||
},
|
||||
|
@ -30,7 +30,7 @@ M.telescope = {
|
|||
{
|
||||
box = "vertical",
|
||||
{ win = "list", title = " Results ", title_pos = "center", border = "rounded" },
|
||||
{ win = "input", height = 1, border = "rounded", title = "{source} {live} {flags}", title_pos = "center" },
|
||||
{ win = "input", height = 1, border = "rounded", title = "{title} {live} {flags}", title_pos = "center" },
|
||||
},
|
||||
{
|
||||
win = "preview",
|
||||
|
@ -50,7 +50,7 @@ M.ivy = {
|
|||
width = 0,
|
||||
height = 0.4,
|
||||
border = "top",
|
||||
title = " {source} {live} {flags}",
|
||||
title = " {title} {live} {flags}",
|
||||
title_pos = "left",
|
||||
{ win = "input", height = 1, border = "bottom" },
|
||||
{
|
||||
|
@ -74,7 +74,7 @@ M.dropdown = {
|
|||
{
|
||||
box = "vertical",
|
||||
border = "rounded",
|
||||
title = "{source} {live} {flags}",
|
||||
title = "{title} {live} {flags}",
|
||||
title_pos = "center",
|
||||
{ win = "input", height = 1, border = "bottom" },
|
||||
{ win = "list", border = "none" },
|
||||
|
@ -91,7 +91,7 @@ M.vertical = {
|
|||
min_height = 30,
|
||||
box = "vertical",
|
||||
border = "rounded",
|
||||
title = "{source} {live} {flags}",
|
||||
title = "{title} {live} {flags}",
|
||||
title_pos = "center",
|
||||
{ win = "input", height = 1, border = "bottom" },
|
||||
{ win = "list", border = "none" },
|
||||
|
@ -127,7 +127,7 @@ M.vscode = {
|
|||
height = 0.4,
|
||||
border = "none",
|
||||
box = "vertical",
|
||||
{ win = "input", height = 1, border = "rounded", title = "{source} {live} {flags}", title_pos = "center" },
|
||||
{ win = "input", height = 1, border = "rounded", title = "{title} {live} {flags}", title_pos = "center" },
|
||||
{ win = "list", border = "hpad" },
|
||||
{ win = "preview", title = "{preview}", border = "rounded" },
|
||||
},
|
||||
|
|
|
@ -19,7 +19,7 @@ Async.BUDGET = 10
|
|||
---@field sort snacks.picker.sort
|
||||
---@field updater uv.uv_timer_t
|
||||
---@field start_time number
|
||||
---@field source_name string
|
||||
---@field title string
|
||||
---@field closed? boolean
|
||||
---@field hist_idx number
|
||||
---@field hist_cursor number
|
||||
|
@ -100,7 +100,7 @@ function M.new(opts)
|
|||
topline = self.list.top,
|
||||
}
|
||||
|
||||
self.source_name = Snacks.picker.util.title(self.opts.source or "search")
|
||||
self.title = self.opts.title or Snacks.picker.util.title(self.opts.source or "search")
|
||||
|
||||
-- properly close the picker when the window is closed
|
||||
self.input.win:on("WinClosed", function()
|
||||
|
@ -211,7 +211,8 @@ end
|
|||
---@hide
|
||||
function M:update_titles()
|
||||
local data = {
|
||||
source = self.source_name,
|
||||
source = self.title,
|
||||
title = self.title,
|
||||
live = self.opts.live and self.opts.icons.ui.live or "",
|
||||
preview = vim.trim(self.preview.title or ""),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue