tangled
alpha
login
or
join now
robinwobin.dev
/
artio.nvim
3
fork
atom
minimal extui fuzzy finder for neovim
3
fork
atom
overview
issues
pulls
pipelines
feat: add `hl_item()` field
robinwobin.dev
3 months ago
a5f215a2
fff72a8e
+26
-1
2 changed files
expand all
collapse all
unified
split
lua
artio
picker.lua
view.lua
+3
-1
lua/artio/picker.lua
···
1
1
local View = require("artio.view")
2
2
3
3
-
---@alias artio.Picker.item { id: integer, v: string, text: string, icon?: string, icon_hl?: string }
3
3
+
---@alias artio.Picker.item { id: integer, v: string, text: string, icon?: string, icon_hl?: string, hls?: artio.Picker.hl[] }
4
4
---@alias artio.Picker.match [integer, integer[], integer] [item, pos[], score]
5
5
---@alias artio.Picker.sorter fun(lst: artio.Picker.item[], input: string): artio.Picker.match[]
6
6
+
---@alias artio.Picker.hl [[integer, integer], string]
6
7
7
8
---@class artio.Picker.proto<T>
8
9
---@field items? artio.Picker.item[]
···
11
12
---@field format_item? fun(item: string): string
12
13
---@field preview_item? fun(item: string): integer, fun(win: integer)
13
14
---@field get_icon? fun(item: artio.Picker.item): string, string
15
15
+
---@field hl_item? fun(item: artio.Picker.item): artio.Picker.hl[]
14
16
---@field opts? artio.config.opts
15
17
---@field win? artio.config.win
16
18
---@field prompt? string
+23
lua/artio/view.lua
···
376
376
local lines = {} ---@type string[]
377
377
local hls = {}
378
378
local icons = {} ---@type ([string, string]|false)[]
379
379
+
local custom_hls = {} ---@type (artio.Picker.hl[]|false)[]
379
380
for i = 1 + offset, math.min(#self.picker.matches, maxlistheight + offset) do
380
381
local match = self.picker.matches[i]
381
382
local item = self.picker.items[match[1]]
···
387
388
end
388
389
icons[#icons + 1] = icon and { icon, icon_hl } or false
389
390
icon = icon and ("%s%s"):format(item.icon, icon_pad_str) or ""
391
391
+
392
392
+
local hl = item.hls
393
393
+
if not hl and vim.is_callable(self.picker.hl_item) then
394
394
+
hl = self.picker.hl_item(item)
395
395
+
item.hls = hl
396
396
+
end
397
397
+
custom_hls[#custom_hls + 1] = hl or false
390
398
391
399
lines[#lines + 1] = ("%s%s%s"):format(prefix, icon, item.text)
392
400
hls[#hls + 1] = match[2]
···
413
421
hl_group = icons[i][2],
414
422
})
415
423
)
424
424
+
end
425
425
+
426
426
+
local line_hls = custom_hls[i]
427
427
+
if line_hls then
428
428
+
for j = 1, #line_hls do
429
429
+
local hl = line_hls[j]
430
430
+
self:mark(
431
431
+
cmdline.srow + i - 1,
432
432
+
indent + hl[1][1],
433
433
+
vim.tbl_extend("force", ext_match_opts, {
434
434
+
end_col = indent + hl[1][2],
435
435
+
hl_group = hl[2],
436
436
+
})
437
437
+
)
438
438
+
end
416
439
end
417
440
418
441
if hls[i] then