File tree 2 files changed +35
-9
lines changed
2 files changed +35
-9
lines changed Original file line number Diff line number Diff line change @@ -67,25 +67,32 @@ function M:_add(value) end
67
67
--- @protected
68
68
function M :_del (value ) end
69
69
70
+ --- @return string
71
+ function M :key (value )
72
+ return value
73
+ end
74
+
70
75
--- @param plugin LazyPlugin
71
76
function M :add (plugin )
72
77
for _ , value in ipairs (plugin [self .type ] or {}) do
73
- if not self .active [value ] then
74
- self .active [value ] = {}
78
+ local key = self :key (value )
79
+ if not self .active [key ] then
80
+ self .active [key ] = {}
75
81
self :_add (value )
76
82
end
77
- self .active [value ][plugin .name ] = plugin .name
83
+ self .active [key ][plugin .name ] = plugin .name
78
84
end
79
85
end
80
86
81
87
--- @param plugin LazyPlugin
82
88
function M :del (plugin )
83
89
for _ , value in ipairs (plugin [self .type ] or {}) do
84
- if self .active [value ] and self .active [value ][plugin .name ] then
85
- self .active [value ][plugin .name ] = nil
86
- if vim .tbl_isempty (self .active [value ]) then
90
+ local key = self :key (value )
91
+ if self .active [key ] and self .active [key ][plugin .name ] then
92
+ self .active [key ][plugin .name ] = nil
93
+ if vim .tbl_isempty (self .active [key ]) then
87
94
self :_del (value )
88
- self .active [value ] = nil
95
+ self .active [key ] = nil
89
96
end
90
97
end
91
98
end
Original file line number Diff line number Diff line change 29
29
--- @param value string | LazyKeys
30
30
function M .parse (value )
31
31
local ret = vim .deepcopy (value )
32
- ret = ( type (ret ) == " string" and { ret } or ret ) --[[ @as LazyKeys]]
32
+ ret = type (ret ) == " string" and { ret } or ret --[[ @as LazyKeys]]
33
33
ret .mode = ret .mode or " n"
34
34
return ret
35
35
end
@@ -44,14 +44,33 @@ function M.opts(keys)
44
44
return opts
45
45
end
46
46
47
+ --- @return string
48
+ function M :key (value )
49
+ if type (value ) == " string" then
50
+ return value
51
+ end
52
+ local mode = value .mode or { " n" }
53
+ if type (mode ) == " string" then
54
+ mode = { mode }
55
+ end
56
+ --- @type string
57
+ local ret = value [1 ]
58
+ if # mode > 0 then
59
+ ret = table.concat (mode , " ," ) .. " : " .. ret
60
+ end
61
+ return ret
62
+ end
63
+
47
64
--- @param value string | LazyKeys
48
65
function M :_add (value )
49
66
local keys = M .parse (value )
50
67
local lhs = keys [1 ]
51
68
local opts = M .opts (keys )
69
+ opts .noremap = true
52
70
vim .keymap .set (keys .mode , lhs , function ()
71
+ pcall (vim .keymap .del , keys .mode , lhs )
53
72
Util .track ({ keys = lhs })
54
- Loader .load (self .active [value ], { keys = lhs })
73
+ Loader .load (self .active [self : key ( value ) ], { keys = lhs })
55
74
M .retrigger (lhs )
56
75
Util .track ()
57
76
end , opts )
You can’t perform that action at this time.
0 commit comments