mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 19:28:24 +00:00
feat(picker): syntax highlighting for command and search history
This commit is contained in:
parent
f7d07bcbc2
commit
efb6d1f8b8
3 changed files with 15 additions and 7 deletions
|
@ -118,6 +118,9 @@ local defaults = {
|
||||||
ui_select = true, -- replace `vim.ui.select` with the snacks picker
|
ui_select = true, -- replace `vim.ui.select` with the snacks picker
|
||||||
---@class snacks.picker.formatters.Config
|
---@class snacks.picker.formatters.Config
|
||||||
formatters = {
|
formatters = {
|
||||||
|
text = {
|
||||||
|
ft = nil, ---@type string? filetype for highlighting
|
||||||
|
},
|
||||||
file = {
|
file = {
|
||||||
filename_first = false, -- display filename before the file path
|
filename_first = false, -- display filename before the file path
|
||||||
},
|
},
|
||||||
|
|
|
@ -71,6 +71,7 @@ M.command_history = {
|
||||||
preset = "vscode",
|
preset = "vscode",
|
||||||
},
|
},
|
||||||
confirm = "cmd",
|
confirm = "cmd",
|
||||||
|
formatters = { text = { ft = "vim" } },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Neovim commands
|
-- Neovim commands
|
||||||
|
@ -549,10 +550,9 @@ M.search_history = {
|
||||||
name = "search",
|
name = "search",
|
||||||
format = "text",
|
format = "text",
|
||||||
preview = "none",
|
preview = "none",
|
||||||
layout = {
|
layout = { preset = "vscode" },
|
||||||
preset = "vscode",
|
|
||||||
},
|
|
||||||
confirm = "search",
|
confirm = "search",
|
||||||
|
formatters = { text = { ft = "regex" } },
|
||||||
}
|
}
|
||||||
|
|
||||||
---@class snacks.picker.smart.Config: snacks.picker.Config
|
---@class snacks.picker.smart.Config: snacks.picker.Config
|
||||||
|
|
|
@ -275,10 +275,15 @@ function M.lines(item)
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.text(item)
|
function M.text(item, picker)
|
||||||
return {
|
local ret = {} ---@type snacks.picker.Highlight[]
|
||||||
{ item.text },
|
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
|
end
|
||||||
|
|
||||||
function M.command(item)
|
function M.command(item)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue