feat(picker.input): search syntax highlighting

This commit is contained in:
Folke Lemaitre 2025-02-02 23:18:38 +01:00
parent ac76e8ea36
commit 4242f90268
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -27,6 +27,9 @@ function M.new(picker)
vim.fn.prompt_setprompt(win.buf, "")
vim.bo[win.buf].modified = false
end,
on_win = function()
self:highlights()
end,
bo = {
filetype = "snacks_picker_input",
buftype = "prompt",
@ -74,6 +77,17 @@ function M.new(picker)
return self
end
function M:highlights()
local m = vim.fn.matchadd
vim.api.nvim_win_call(self.win.win, function()
m("@punctuation.delimiter", "\\v(^|\\s|:|\\!)\\zs['^]")
m("@punctuation.delimiter", "\\v['$]\\ze(\\s|$)")
m("DiagnosticWarn", "\\v(^|\\s|:)\\zs\\!")
m("@keyword", "\\v(^|\\s)\\zs\\w+:")
m("@operator", "\\v\\s\\zs\\|\\ze\\s")
end)
end
function M:close()
self.win:destroy()
self.picker = nil -- needed for garbage collection of the picker