minimal extui fuzzy finder for neovim

feat: track active picker

+28 -11
+4
lua/artio/init.lua
··· 68 68 ---@param ... artio.Picker.proto 69 69 artio.pick = function(...) 70 70 local Picker = require("artio.picker") 71 + if artio.active_picker then 72 + artio.active_picker:close() 73 + end 74 + artio.active_picker = Picker 71 75 return Picker:new(...):open() 72 76 end 73 77
+24 -11
lua/artio/picker.lua
··· 26 26 vim.validate("on_close", props.on_close, "function") 27 27 28 28 local t = vim.tbl_deep_extend("force", { 29 + closed = false, 29 30 prompt = "", 30 31 idx = 1, 31 32 items = {}, ··· 62 63 local accepted 63 64 local cancelled 64 65 65 - local view = View:new() 66 - view.picker = self 66 + self.view = View:new() 67 + self.view.picker = self 67 68 68 69 coroutine.wrap(function() 69 - view:open() 70 + self.view:open() 70 71 71 72 local co, ismain = coroutine.running() 72 73 assert(not ismain, "must be called from a coroutine") 73 74 74 - local key_ns = vim.on_key(function(_, typed) 75 - if view.closed then 75 + self.key_ns = vim.on_key(function(_, typed) 76 + if self.view.closed then 76 77 coroutine.resume(co) 77 78 return 78 79 end ··· 80 81 typed = string.lower(vim.fn.keytrans(typed)) 81 82 if typed == "<down>" then 82 83 self.idx = self.idx + 1 83 - view:showmatches() 84 - view:hlselect() 84 + self.view:showmatches() 85 + self.view:hlselect() 85 86 return "" 86 87 elseif typed == "<up>" then 87 88 self.idx = self.idx - 1 88 - view:showmatches() 89 - view:hlselect() 89 + self.view:showmatches() 90 + self.view:hlselect() 90 91 return "" 91 92 elseif typed == "<cr>" then 92 93 accepted = true ··· 101 102 102 103 coroutine.yield() 103 104 104 - vim.on_key(nil, key_ns) 105 - view:close() 105 + self:close() 106 106 107 107 if cancelled or not accepted then 108 108 return ··· 117 117 118 118 self.on_close(item.v, item.id) 119 119 end)() 120 + end 121 + 122 + function Picker:close() 123 + if self.closed then 124 + return 125 + end 126 + 127 + vim.on_key(nil, self.key_ns) 128 + if self.view then 129 + self.view:close() 130 + end 131 + 132 + self.closed = true 120 133 end 121 134 122 135 function Picker:fix()