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: track active picker
robinwobin.dev
4 months ago
837b7ad6
4870f2b0
+28
-11
2 changed files
expand all
collapse all
unified
split
lua
artio
init.lua
picker.lua
+4
lua/artio/init.lua
···
68
68
---@param ... artio.Picker.proto
69
69
artio.pick = function(...)
70
70
local Picker = require("artio.picker")
71
71
+
if artio.active_picker then
72
72
+
artio.active_picker:close()
73
73
+
end
74
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
29
+
closed = false,
29
30
prompt = "",
30
31
idx = 1,
31
32
items = {},
···
62
63
local accepted
63
64
local cancelled
64
65
65
65
-
local view = View:new()
66
66
-
view.picker = self
66
66
+
self.view = View:new()
67
67
+
self.view.picker = self
67
68
68
69
coroutine.wrap(function()
69
69
-
view:open()
70
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
74
-
local key_ns = vim.on_key(function(_, typed)
75
75
-
if view.closed then
75
75
+
self.key_ns = vim.on_key(function(_, typed)
76
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
83
-
view:showmatches()
84
84
-
view:hlselect()
84
84
+
self.view:showmatches()
85
85
+
self.view:hlselect()
85
86
return ""
86
87
elseif typed == "<up>" then
87
88
self.idx = self.idx - 1
88
88
-
view:showmatches()
89
89
-
view:hlselect()
89
89
+
self.view:showmatches()
90
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
104
-
vim.on_key(nil, key_ns)
105
105
-
view:close()
105
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
120
+
end
121
121
+
122
122
+
function Picker:close()
123
123
+
if self.closed then
124
124
+
return
125
125
+
end
126
126
+
127
127
+
vim.on_key(nil, self.key_ns)
128
128
+
if self.view then
129
129
+
self.view:close()
130
130
+
end
131
131
+
132
132
+
self.closed = true
120
133
end
121
134
122
135
function Picker:fix()