From daebb30699f6267e137892a37a5bad2be7153e4e Mon Sep 17 00:00:00 2001 From: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> Date: Fri, 24 Jan 2025 23:43:18 -0800 Subject: [PATCH] fix(gitsigns.keymap): update functions and descriptions This commit is a follow-up fix for #1405: - `stage_hunk` now toggles between staging and unstaging a hunk (keymap description updated). - Changed the callback for `text_object` to `select_hunk`: ``` > git log --grep text_object commit e22e37897ac328d3f7e00e354852b6c9ffdd1e5d Author: Lewis Russell Date: Thu Mar 25 14:47:33 2021 +0000 Rename text_object() -> select_hunk() ``` Signed-off-by: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> --- lua/keymap/ui.lua | 114 ++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/lua/keymap/ui.lua b/lua/keymap/ui.lua index 7b3c8f2bc..68af9737a 100644 --- a/lua/keymap/ui.lua +++ b/lua/keymap/ui.lua @@ -2,6 +2,7 @@ local bind = require("keymap.bind") local map_cr = bind.map_cr local map_cu = bind.map_cu local map_cmd = bind.map_cmd +local map_callback = bind.map_callback local mappings = { builtins = { @@ -86,70 +87,83 @@ bind.nvim_load_mapping(mappings.plugins) local M = {} -function M.gitsigns(buf) +function M.gitsigns(bufnr) local actions = require("gitsigns.actions") local map = { - ["n|]g"] = bind.map_callback(function() - if vim.wo.diff then - return "]g" - end - vim.schedule(function() - actions.next_hunk() + ["n|]g"] = map_callback(function() + if vim.wo.diff then + return "]g" + end + vim.schedule(function() + actions.next_hunk() + end) + return "" end) - return "" - end) - :with_buffer(buf) + :with_buffer(bufnr) + :with_noremap() :with_expr() :with_desc("git: Goto next hunk"), - ["n|[g"] = bind.map_callback(function() - if vim.wo.diff then - return "[g" - end - vim.schedule(function() - actions.prev_hunk() + ["n|[g"] = map_callback(function() + if vim.wo.diff then + return "[g" + end + vim.schedule(function() + actions.prev_hunk() + end) + return "" end) - return "" - end) - :with_buffer(buf) + :with_buffer(bufnr) + :with_noremap() :with_expr() :with_desc("git: Goto prev hunk"), - ["n|gs"] = bind.map_callback(function() - actions.stage_hunk() - end) - :with_buffer(buf) - :with_desc("git: Stage hunk"), - ["v|gs"] = bind.map_callback(function() - actions.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) - end) - :with_buffer(buf) - :with_desc("git: Stage hunk"), - ["n|gr"] = bind.map_callback(function() - actions.reset_hunk() - end) - :with_buffer(buf) + ["n|gs"] = map_callback(function() + actions.stage_hunk() + end) + :with_buffer(bufnr) + :with_noremap() + :with_desc("git: Toggle staging/unstaging of hunk"), + ["v|gs"] = map_callback(function() + actions.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) + end) + :with_buffer(bufnr) + :with_noremap() + :with_desc("git: Toggle staging/unstaging of selected hunk"), + ["n|gr"] = map_callback(function() + actions.reset_hunk() + end) + :with_buffer(bufnr) + :with_noremap() :with_desc("git: Reset hunk"), - ["v|gr"] = bind.map_callback(function() - actions.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) - end) - :with_buffer(buf) + ["v|gr"] = map_callback(function() + actions.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) + end) + :with_buffer(bufnr) + :with_noremap() :with_desc("git: Reset hunk"), - ["n|gR"] = bind.map_callback(function() - actions.reset_buffer() - end) - :with_buffer(buf) + ["n|gR"] = map_callback(function() + actions.reset_buffer() + end) + :with_buffer(bufnr) + :with_noremap() :with_desc("git: Reset buffer"), - ["n|gp"] = bind.map_callback(function() - actions.preview_hunk() - end) - :with_buffer(buf) + ["n|gp"] = map_callback(function() + actions.preview_hunk() + end) + :with_buffer(bufnr) + :with_noremap() :with_desc("git: Preview hunk"), - ["n|gb"] = bind.map_callback(function() - actions.blame_line({ full = true }) - end) - :with_buffer(buf) + ["n|gb"] = map_callback(function() + actions.blame_line({ full = true }) + end) + :with_buffer(bufnr) + :with_noremap() :with_desc("git: Blame line"), -- Text objects - ["ox|ih"] = bind.map_cu("Gitsigns select_hunk"):with_silent():with_buffer(buf), + ["ox|ih"] = map_callback(function() + actions.select_hunk() + end) + :with_buffer(bufnr) + :with_noremap(), } bind.nvim_load_mapping(map) end