fix(select_hunk): compatible with <cmd> mapping

This commit is contained in:
xzb 2025-02-04 23:36:02 +08:00 committed by Lewis Russell
parent 71e8204f91
commit 8974fd397e
2 changed files with 6 additions and 2 deletions

View File

@ -181,7 +181,7 @@ require('gitsigns').setup{
map('n', '<leader>tw', gitsigns.toggle_word_diff)
-- Text object
map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
map({'o', 'x'}, 'ih', '<cmd>Gitsigns select_hunk<CR>')
end
}
```

View File

@ -951,7 +951,11 @@ M.select_hunk = function(opts)
return
end
vim.cmd('normal! ' .. hunk.added.start .. 'GV' .. hunk.vend .. 'G')
if vim.fn.mode():find('v') ~= nil then
vim.cmd('normal! ' .. hunk.added.start .. 'GoV' .. hunk.vend .. 'G')
else
vim.cmd('normal! ' .. hunk.added.start .. 'GV' .. hunk.vend .. 'G')
end
end
--- Get hunk array for specified buffer.