feat: Simplify wkSpec func
This commit is contained in:
parent
df3282c64d
commit
d8949f0cee
5 changed files with 37 additions and 47 deletions
|
@ -21,44 +21,20 @@ end
|
|||
|
||||
---Generates a function that can be used to create which-key mappings.
|
||||
---@param color string The color to use for the icon.
|
||||
---@param setRhs? boolean Whether to allow setting the rhs.
|
||||
---@return function
|
||||
function M.wkSpec(color, setRhs)
|
||||
if setRhs then
|
||||
---@param lhs string
|
||||
---@param rhs string | fun()
|
||||
---@param icon string | wk.Icon
|
||||
---@param opts? wk.Spec
|
||||
return function(lhs, rhs, icon, opts)
|
||||
if type(icon) == 'string' then
|
||||
icon = { icon = icon, color = color }
|
||||
else
|
||||
icon = vim.tbl_deep_extend('force', icon, { color = color })
|
||||
end
|
||||
|
||||
return vim.tbl_deep_extend(
|
||||
'force',
|
||||
{ lhs, rhs, icon = icon },
|
||||
(opts or {})
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function M.wkSpec(color)
|
||||
---@param lhs string
|
||||
---@param rhs string | fun()
|
||||
---@param icon string | wk.Icon
|
||||
---@param opts? wk.Spec
|
||||
return function(lhs, icon, opts)
|
||||
return function(lhs, rhs, icon, opts)
|
||||
if type(icon) == 'string' then
|
||||
icon = { icon = icon, color = color }
|
||||
else
|
||||
icon = vim.tbl_deep_extend('force', icon, { color = color })
|
||||
end
|
||||
|
||||
return vim.tbl_deep_extend(
|
||||
'force',
|
||||
{ lhs, icon = { icon = icon, color = color } },
|
||||
(opts or {})
|
||||
)
|
||||
return vim.tbl_deep_extend('force', { lhs, rhs, icon = icon }, (opts or {}))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -51,11 +51,11 @@ return {
|
|||
|
||||
local mkKey = MarleyVim.wkSpec(require('colors').search)
|
||||
require('which-key').add({
|
||||
mkKey('s', '', { mode = { 'n', 'x', 'o' } }),
|
||||
mkKey('S', '', { mode = { 'n', 'x', 'o' } }),
|
||||
mkKey('r', '', { mode = { 'o' } }),
|
||||
mkKey('r', '', { mode = { 'x', 'o' } }),
|
||||
mkKey('<C-s>', '', { mode = { 'c' } }),
|
||||
mkKey('s', nil, '', { mode = { 'n', 'x', 'o' } }),
|
||||
mkKey('S', nil, '', { mode = { 'n', 'x', 'o' } }),
|
||||
mkKey('r', nil, '', { mode = { 'o' } }),
|
||||
mkKey('r', nil, '', { mode = { 'x', 'o' } }),
|
||||
mkKey('<C-s>', nil, '', { mode = { 'c' } }),
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ return {
|
|||
local gitsigns = package.loaded.gitsigns
|
||||
|
||||
local icons = require('icons')
|
||||
local mkKey = MarleyVim.wkSpec(require('colors').git, true)
|
||||
local mkKey = MarleyVim.wkSpec(require('colors').git)
|
||||
require('which-key').add({
|
||||
mkKey(']h', function()
|
||||
if vim.wo.diff then
|
||||
|
@ -34,6 +34,7 @@ return {
|
|||
gitsigns.nav_hunk('next')
|
||||
end
|
||||
end, icons.next, { desc = 'next hunk' }),
|
||||
|
||||
mkKey('[h', function()
|
||||
if vim.wo.diff then
|
||||
vim.cmd.normal({ '[c', bang = true })
|
||||
|
@ -41,68 +42,81 @@ return {
|
|||
gitsigns.nav_hunk('prev')
|
||||
end
|
||||
end, icons.prev, { desc = 'previous hunk' }),
|
||||
|
||||
mkKey(']H', function()
|
||||
gitsigns.nav_hunk('last')
|
||||
end, icons.last, { desc = 'last hunk' }),
|
||||
|
||||
mkKey('[H', function()
|
||||
gitsigns.nav_hunk('first')
|
||||
end, icons.first, { desc = 'first hunk' }),
|
||||
|
||||
mkKey(
|
||||
'<LEADER>ghs',
|
||||
'<CMD>Gitsigns stage_hunk<CR>',
|
||||
icons.git.staged,
|
||||
{ mode = { 'n', 'v' }, desc = 'stage hunk' }
|
||||
),
|
||||
|
||||
mkKey(
|
||||
'<LEADER>ghr',
|
||||
'<CMD>Gitsigns reset_hunk<CR>',
|
||||
icons.git.unstaged,
|
||||
{ mode = { 'n', 'v' }, desc = 'reset hunk' }
|
||||
),
|
||||
|
||||
mkKey(
|
||||
'<LEADER>ghS',
|
||||
gitsigns.stage_buffer,
|
||||
icons.git.staged,
|
||||
{ desc = 'stage buffer' }
|
||||
),
|
||||
|
||||
mkKey(
|
||||
'<LEADER>ghu',
|
||||
gitsigns.undo_stage_hunk,
|
||||
icons.undo,
|
||||
{ desc = 'undo stage hunk' }
|
||||
),
|
||||
|
||||
mkKey(
|
||||
'<LEADER>ghR',
|
||||
gitsigns.reset_buffer,
|
||||
icons.git.unstaged,
|
||||
{ desc = 'reset buffer' }
|
||||
),
|
||||
|
||||
mkKey(
|
||||
'<LEADER>ghp',
|
||||
gitsigns.preview_hunk_inline,
|
||||
'',
|
||||
{ desc = 'preview hunk inline' }
|
||||
),
|
||||
|
||||
mkKey('<LEADER>ghb', function()
|
||||
gitsigns.blame_line({ full = true })
|
||||
end, { cat = 'filetype', name = 'git' }, {
|
||||
desc = 'blame line',
|
||||
}),
|
||||
|
||||
mkKey(
|
||||
'<LEADER>ghB',
|
||||
gitsigns.blame,
|
||||
{ cat = 'filetype', name = 'git' },
|
||||
{ desc = 'blame buffer' }
|
||||
),
|
||||
|
||||
mkKey(
|
||||
'<LEADER>ghd',
|
||||
gitsigns.diffthis,
|
||||
icons.git.diff,
|
||||
{ desc = 'diff file' }
|
||||
),
|
||||
|
||||
mkKey('<LEADER>ghD', function()
|
||||
gitsigns.diffthis('~')
|
||||
end, icons.git.diff, { desc = 'diff file from ~' }),
|
||||
|
||||
mkKey(
|
||||
'ih',
|
||||
'<CMD><C-u>Gitsigns select_hunk<CR>',
|
||||
|
|
|
@ -94,16 +94,16 @@ return {
|
|||
local mkKey = MarleyVim.wkSpec(colors.buffers)
|
||||
|
||||
require('which-key').add({
|
||||
mkKey('<LEADER>bp', ''),
|
||||
mkKey('<LEADER>bP', ''),
|
||||
mkKey('<LEADER>br', ''),
|
||||
mkKey('<LEADER>bl', ''),
|
||||
mkKey('<S-H>', ''),
|
||||
mkKey('<S-L>', ''),
|
||||
mkKey('[b', ''),
|
||||
mkKey(']b', ''),
|
||||
mkKey('[B', ''),
|
||||
mkKey(']B', ''),
|
||||
mkKey('<LEADER>bp', nil, ''),
|
||||
mkKey('<LEADER>bP', nil, ''),
|
||||
mkKey('<LEADER>br', nil, ''),
|
||||
mkKey('<LEADER>bl', nil, ''),
|
||||
mkKey('<S-H>', nil, ''),
|
||||
mkKey('<S-L>', nil, ''),
|
||||
mkKey('[b', nil, ''),
|
||||
mkKey(']b', nil, ''),
|
||||
mkKey('[B', nil, ''),
|
||||
mkKey(']B', nil, ''),
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
|
|
@ -105,9 +105,9 @@ return {
|
|||
|
||||
local mkKey = MarleyVim.wkSpec(require('colors').notifications)
|
||||
require('which-key').add({
|
||||
mkKey('<S-ENTER>', '', { mode = 'c' }),
|
||||
mkKey('<C-f>', '', { mode = { 'i', 'n', 's' } }),
|
||||
mkKey('<C-b>', '', { mode = { 'i', 'n', 's' } }),
|
||||
mkKey('<S-ENTER>', nil, '', { mode = 'c' }),
|
||||
mkKey('<C-f>', nil, '', { mode = { 'i', 'n', 's' } }),
|
||||
mkKey('<C-b>', nil, '', { mode = { 'i', 'n', 's' } }),
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue