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