Skip to content
This repository was archived by the owner on Dec 7, 2025. It is now read-only.

Commit db3dba4

Browse files
author
Caio Daniel Nunes Santos
committed
Allow mapping to be created inside plugin setup, but still specified as
a trigger to load the plugin.
1 parent e268601 commit db3dba4

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lua/strive/init.lua

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -932,21 +932,26 @@ function Plugin:keys(mappings)
932932
if type(mapping) == 'table' then
933933
mode = mapping[1] or 'n'
934934
lhs = mapping[2]
935-
rhs = mapping[3] or function() end
935+
rhs = mapping[3]
936936
opts = mapping[4] or {}
937937
else
938938
mode, lhs = 'n', mapping
939-
rhs = function() end
940939
opts = {}
941940
end
942941

943942
-- Create a keymap that loads the plugin first
944943
vim.keymap.set(mode, lhs, function()
945-
if self:load() and type(rhs) == 'function' then
946-
rhs()
947-
elseif self:load() and type(rhs) == 'string' then
948-
-- If rhs is a string command
949-
vim.cmd(rhs)
944+
if type(rhs) == 'function' then
945+
self:load(nil, rhs)
946+
elseif type(rhs) == 'string' then
947+
self:load(nil, function() vim.cmd(rhs) end)
948+
elseif type(rhs) == 'nil' then
949+
-- If rhs not specified, it should be defined in plugin config
950+
-- In this case, we need to pass a callback
951+
self:load(nil, function()
952+
vim.schedule(function()
953+
vim.fn.feedkeys(lhs)
954+
end) end)
950955
end
951956
end, opts)
952957
end

0 commit comments

Comments
 (0)