feat(picker): syntax highlighting for command and search history

This commit is contained in:
Folke Lemaitre 2025-01-21 22:21:16 +01:00
parent f7d07bcbc2
commit efb6d1f8b8
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 15 additions and 7 deletions

View file

@ -118,6 +118,9 @@ local defaults = {
ui_select = true, -- replace `vim.ui.select` with the snacks picker
---@class snacks.picker.formatters.Config
formatters = {
text = {
ft = nil, ---@type string? filetype for highlighting
},
file = {
filename_first = false, -- display filename before the file path
},

View file

@ -71,6 +71,7 @@ M.command_history = {
preset = "vscode",
},
confirm = "cmd",
formatters = { text = { ft = "vim" } },
}
-- Neovim commands
@ -549,10 +550,9 @@ M.search_history = {
name = "search",
format = "text",
preview = "none",
layout = {
preset = "vscode",
},
layout = { preset = "vscode" },
confirm = "search",
formatters = { text = { ft = "regex" } },
}
---@class snacks.picker.smart.Config: snacks.picker.Config

View file

@ -275,10 +275,15 @@ function M.lines(item)
return ret
end
function M.text(item)
return {
{ item.text },
}
function M.text(item, picker)
local ret = {} ---@type snacks.picker.Highlight[]
local ft = item.ft or picker.opts.formatters.text.ft
if ft then
Snacks.picker.highlight.format(item, item.text, ret, { lang = ft })
else
ret[#ret + 1] = { item.text }
end
return ret
end
function M.command(item)