minimal extui fuzzy finder for neovim

feat: allow custom mappings and actions

+17 -23
+8 -14
lua/artio/actions.lua
··· 43 end 44 45 typed = string.lower(vim.fn.keytrans(typed)) 46 - if typed == "<down>" then 47 - self.actions.down(self.picker, self.co) 48 - return "" 49 - elseif typed == "<up>" then 50 - self.actions.up(self.picker, self.co) 51 - return "" 52 - elseif typed == "<cr>" then 53 - self.actions.accept(self.picker, self.co) 54 - return "" 55 - elseif typed == "<esc>" then 56 - self.actions.cancel(self.picker, self.co) 57 - return "" 58 - elseif typed == "<c-l>" then 59 - self.actions.togglepreview(self.picker, self.co) 60 return "" 61 end 62 end
··· 43 end 44 45 typed = string.lower(vim.fn.keytrans(typed)) 46 + 47 + local _, actionname = vim.iter(pairs(self.picker.mappings)):find(function(key, _) 48 + return key == typed 49 + end) 50 + 51 + local action = self.actions[actionname] 52 + if action and vim.is_callable(action) then 53 + action(self.picker, self.co) 54 return "" 55 end 56 end
+9 -9
lua/artio/picker.lua
··· 32 33 ---@type table<string, fun(self: artio.Picker, co: thread)> 34 local default_actions = { 35 - down = function(self, co) 36 self.idx = self.idx + 1 37 self.view:showmatches() 38 self.view:hlselect() 39 end, 40 - up = function(self, co) 41 self.idx = self.idx - 1 42 self.view:showmatches() 43 self.view:hlselect() 44 end, 45 - accept = function(self, co) 46 coroutine.resume(co, action_enum.accept) 47 end, 48 - cancel = function(self, co) 49 coroutine.resume(co, action_enum.cancel) 50 - self.view:togglepreview() 51 end, 52 - togglepreview = function(self, co) 53 self.view:togglepreview() 54 end, 55 } ··· 109 return 110 end 111 112 - local current = self.matches[self.idx][1] 113 if not current then 114 return 115 end 116 117 local item = self.items[current] 118 - 119 - self.on_close(item.v, item.id) 120 end)() 121 end 122
··· 32 33 ---@type table<string, fun(self: artio.Picker, co: thread)> 34 local default_actions = { 35 + down = function(self, _) 36 self.idx = self.idx + 1 37 self.view:showmatches() 38 self.view:hlselect() 39 end, 40 + up = function(self, _) 41 self.idx = self.idx - 1 42 self.view:showmatches() 43 self.view:hlselect() 44 end, 45 + accept = function(_, co) 46 coroutine.resume(co, action_enum.accept) 47 end, 48 + cancel = function(_, co) 49 coroutine.resume(co, action_enum.cancel) 50 end, 51 + togglepreview = function(self, _) 52 self.view:togglepreview() 53 end, 54 } ··· 108 return 109 end 110 111 + local current = self.matches[self.idx] and self.matches[self.idx][1] 112 if not current then 113 return 114 end 115 116 local item = self.items[current] 117 + if item then 118 + self.on_close(item.v, item.id) 119 + end 120 end)() 121 end 122