mirror of
https://github.com/lewis6991/gitsigns.nvim
synced 2024-09-16 14:34:09 +02:00
parent
0dc886637f
commit
93c38d9726
3 changed files with 55 additions and 20 deletions
|
@ -287,9 +287,13 @@ blame({callback?}) *gitsigns.blame()*
|
|||
Run git-blame on the current file and open the results
|
||||
in a scroll-bound vertical split.
|
||||
|
||||
<CR> is mapped to open a menu with the actions:
|
||||
- [Show commit] in a vertical split.
|
||||
- [Reblame at commit]
|
||||
Mappings:
|
||||
<CR> is mapped to open a menu with the other mappings
|
||||
Note: <Alt> must be held to activate the mappings whilst the menu is
|
||||
open.
|
||||
s [Show commit] in a vertical split.
|
||||
S [Show commit] in a new tab.
|
||||
r [Reblame at commit]
|
||||
|
||||
Attributes: ~
|
||||
{async}
|
||||
|
|
|
@ -1053,9 +1053,13 @@ end
|
|||
--- Run git-blame on the current file and open the results
|
||||
--- in a scroll-bound vertical split.
|
||||
---
|
||||
--- <CR> is mapped to open a menu with the actions:
|
||||
--- - [Show commit] in a vertical split.
|
||||
--- - [Reblame at commit]
|
||||
--- Mappings:
|
||||
--- <CR> is mapped to open a menu with the other mappings
|
||||
--- Note: <Alt> must be held to activate the mappings whilst the menu is
|
||||
--- open.
|
||||
--- s [Show commit] in a vertical split.
|
||||
--- S [Show commit] in a new tab.
|
||||
--- r [Reblame at commit]
|
||||
---
|
||||
--- Attributes: ~
|
||||
--- {async}
|
||||
|
|
|
@ -179,14 +179,17 @@ local function reblame(blame, win, revision)
|
|||
)
|
||||
end
|
||||
|
||||
--- @param sha string
|
||||
--- @param git_obj Gitsigns.GitObj
|
||||
local show_commit = async.create(2, function(sha, git_obj)
|
||||
local res = git_obj:command({ 'show', sha })
|
||||
--- @param win integer
|
||||
--- @param open 'vsplit'|'tabnew'
|
||||
--- @param bcache Gitsigns.CacheEntry
|
||||
local show_commit = async.create(3, function(win, open, bcache)
|
||||
local cursor = api.nvim_win_get_cursor(win)[1]
|
||||
local sha = bcache.blame[cursor].commit.sha
|
||||
local res = bcache.git_obj:command({ 'show', sha })
|
||||
async.scheduler()
|
||||
local commit_buf = api.nvim_create_buf(false, true)
|
||||
api.nvim_buf_set_lines(commit_buf, 0, -1, false, res)
|
||||
vim.cmd.vsplit({ mods = { keepalt = true } })
|
||||
vim.cmd[open]({ mods = { keepalt = true } })
|
||||
api.nvim_win_set_buf(0, commit_buf)
|
||||
vim.bo[commit_buf].filetype = 'git'
|
||||
end)
|
||||
|
@ -224,6 +227,24 @@ local function sync_cursors(augroup, wins)
|
|||
end
|
||||
end
|
||||
|
||||
--- @param name string
|
||||
--- @param items [string, string][]
|
||||
local function menu(name, items)
|
||||
local max_len = 0
|
||||
for _, item in ipairs(items) do
|
||||
max_len = math.max(max_len, #item[1]) --- @type integer
|
||||
end
|
||||
|
||||
for _, item in ipairs(items) do
|
||||
local item_nm, action = item[1], item[2]
|
||||
local pad = string.rep(' ', max_len - #item_nm)
|
||||
local lhs = string.format('%s%s (%s)', item_nm, pad, action):gsub(' ', [[\ ]])
|
||||
local cmd = string.format('nmenu <silent> ]%s.%s %s', name, lhs, action)
|
||||
|
||||
vim.cmd(cmd)
|
||||
end
|
||||
end
|
||||
|
||||
--- @async
|
||||
M.blame = function()
|
||||
local __FUNC__ = 'blame'
|
||||
|
@ -284,7 +305,7 @@ M.blame = function()
|
|||
vim.cmd.syncbind()
|
||||
|
||||
vim.keymap.set('n', '<CR>', function()
|
||||
vim.cmd.popup('GitsignsBlame')
|
||||
vim.cmd.popup(']GitsignsBlame')
|
||||
end, {
|
||||
desc = 'Open blame context menu',
|
||||
buffer = blm_bufnr,
|
||||
|
@ -298,18 +319,24 @@ M.blame = function()
|
|||
})
|
||||
|
||||
vim.keymap.set('n', 's', function()
|
||||
local cursor = api.nvim_win_get_cursor(blm_win)[1]
|
||||
local sha = blame[cursor].commit.sha
|
||||
show_commit(sha, bcache.git_obj)
|
||||
show_commit(blm_win, 'vsplit', bcache)
|
||||
end, {
|
||||
desc = 'Show commit',
|
||||
desc = 'Show commit in a vertical split',
|
||||
buffer = blm_bufnr,
|
||||
})
|
||||
|
||||
vim.cmd([[
|
||||
:nnoremenu <silent> GitsignsBlame.Reblame\ at\ commit\ \ (r) r
|
||||
:nnoremenu <silent> GitsignsBlame.Show\ commit\ \ \ \ \ \ \ \ (s) s
|
||||
]])
|
||||
vim.keymap.set('n', 'S', function()
|
||||
show_commit(blm_win, 'tabnew', bcache)
|
||||
end, {
|
||||
desc = 'Show commit in a new tab',
|
||||
buffer = blm_bufnr,
|
||||
})
|
||||
|
||||
menu('GitsignsBlame', {
|
||||
{ 'Reblame at commit', 'r' },
|
||||
{ 'Show commit (vsplit)', 's' },
|
||||
{ ' (tab)', 'S' },
|
||||
})
|
||||
|
||||
local group = api.nvim_create_augroup('GitsignsBlame', {})
|
||||
|
||||
|
|
Loading…
Reference in a new issue