minimal extui fuzzy finder for neovim

feat: add pattern matching to default sorter

+24 -1
+24 -1
lua/artio/init.lua
··· 93 93 end 94 94 95 95 ---@type artio.Picker.sorter 96 - artio.sorter = function(lst, input) 96 + artio.fuzzy_sorter = function(lst, input) 97 97 if not lst or #lst == 0 then 98 98 return {} 99 99 end ··· 112 112 end 113 113 return items 114 114 end 115 + 116 + ---@type artio.Picker.sorter 117 + artio.pattern_sorter = function(lst, input) 118 + local match = string.match(input, "^/[^/]*/") 119 + local pattern = match and string.match(match, "^/([^/]*)/$") 120 + 121 + return vim 122 + .iter(lst) 123 + :map(function(v) 124 + if pattern and not string.match(v.text, pattern) then 125 + return 126 + end 127 + 128 + return { v.id, {}, 0 } 129 + end) 130 + :totable() 131 + end 132 + 133 + ---@type artio.Picker.sorter 134 + artio.sorter = artio.mergesorters("intersect", artio.pattern_sorter, function(lst, input) 135 + input = string.gsub(input, "^/[^/]*/", "") 136 + return artio.fuzzy_sorter(lst, input) 137 + end) 115 138 116 139 ---@generic T 117 140 ---@param items T[] Arbitrary items