From 11201a685d9d4122a4716016bb1f9a1e110e258b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 12 Jul 2024 19:52:03 +0100 Subject: [PATCH] home: vim: git: use lua in visual mappings I thought the partial staging feature had broken, but it looks to be unrelated [1]. [1]: https://github.com/lewis6991/gitsigns.nvim/issues/1088 --- modules/home/vim/plugin/settings/git.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/home/vim/plugin/settings/git.lua b/modules/home/vim/plugin/settings/git.lua index 4dbebca..c35d400 100644 --- a/modules/home/vim/plugin/settings/git.lua +++ b/modules/home/vim/plugin/settings/git.lua @@ -1,6 +1,15 @@ local gitsigns = require("gitsigns") local wk = require("which-key") +--- Transform `f` into a function which acts on the current visual selection +local function make_visual(f) + return function() + local first = vim.fn.line("v") + local last = vim.fn.line(".") + f({ first, last }) + end +end + gitsigns.setup({ current_line_blame_opts = { -- Show the blame quickly @@ -46,10 +55,10 @@ local visual = { -- Only the actual command can make use of the visual selection... ["g"] = { name = "Git", - p = { ":Gitsigns preview_hunk", "Preview selection" }, - r = { ":Gitsigns reset_hunk", "Restore selection" }, - s = { ":Gitsigns stage_hunk", "Stage selection" }, - u = { ":Gitsigns undo_stage_hunk", "Undo stage selection" }, + p = { gitsigns.preview_hunk, "Preview selection" }, + r = { make_visual(gitsigns.reset_hunk), "Restore selection" }, + s = { make_visual(gitsigns.stage_hunk), "Stage selection" }, + u = { gitsigns.undo_stage_hunk, "Undo stage selection" }, }, }