Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(keybinds): add opts arg to remap(_event) #1256

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions lua/neorg/modules/core/keybinds/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,13 @@ module.public = {
bound_keys[neorg_mode][mode][key] = bound_keys[neorg_mode][mode][key] and nil
end,

remap = function(neorg_mode, mode, key, new_rhs)
--- Remaps a key to a specific Neorg mode
---@param neorg_mode string #The Neorg mode to bind to
---@param mode string #The Neovim mode to bind to, e.g. `n` or `i` etc.
---@param key string #The lhs value from `:h vim.keymap.set`
---@param new_rhs string|function #The rhs value from `:h vim.keymap.set`
---@param opts table #The table value from `:h vim.keymap.set`
remap = function(neorg_mode, mode, key, new_rhs, opts)
if neorg_mode ~= "all" and current_mode ~= neorg_mode then
return
end
Expand All @@ -237,12 +243,24 @@ module.public = {
bound_keys[neorg_mode][mode] = bound_keys[neorg_mode][mode] or {}
bound_keys[neorg_mode][mode][key] = bound_keys[neorg_mode][mode][key] or {}

local opts = bound_keys[neorg_mode][mode][key].opts

payload.map(neorg_mode, mode, key, new_rhs, opts)
payload.map(
neorg_mode,
mode,
key,
new_rhs,
vim.tbl_deep_extend("force", bound_keys[neorg_mode][mode][key].opts or {}, opts or {})
)
end,

remap_event = function(neorg_mode, mode, key, new_event)
--- Remaps a key to a specific Neorg keybind.
-- `remap()` binds to any rhs value, whilst `remap_event()` is essentially a wrapper
-- for <cmd>Neorg keybind `neorg_mode` `expr`<CR>
---@param neorg_mode string #The Neorg mode to bind to
---@param mode string #The Neovim mode to bind to, e.g. `n` or `i` etc.
---@param key string #The lhs value from `:h vim.keymap.set`
---@param new_event string #The Neorg event to bind to (e.g. `core.dirman.new.note`)
---@param opts table #The table value from `:h vim.keymap.set`
remap_event = function(neorg_mode, mode, key, new_event, opts)
if neorg_mode ~= "all" and current_mode ~= neorg_mode then
return
end
Expand All @@ -251,14 +269,12 @@ module.public = {
bound_keys[neorg_mode][mode] = bound_keys[neorg_mode][mode] or {}
bound_keys[neorg_mode][mode][key] = bound_keys[neorg_mode][mode][key] or {}

local opts = bound_keys[neorg_mode][mode][key].opts

payload.map(
neorg_mode,
mode,
key,
"<cmd>Neorg keybind " .. neorg_mode .. " " .. new_event .. "<CR>",
opts
vim.tbl_deep_extend("force", bound_keys[neorg_mode][mode][key].opts or {}, opts or {})
)
end,

Expand Down