diff --git a/lua/git/log_view.lua b/lua/git/log_view.lua index 2f63e26..99f2a35 100644 --- a/lua/git/log_view.lua +++ b/lua/git/log_view.lua @@ -7,23 +7,32 @@ local LOG_FORMAT = "%h %ad {%an}%d %s" local cr = vim.api.nvim_replace_termcodes("", true, false, true) +---@param buf integer +---@return boolean opened +local function open_under_cursor(buf) + local r = repo.resolve(buf) + -- Anchor past the leading graph chars (matches the leading sha column, + -- not any hex word that happens to appear later in the subject). + local sha = r + and vim.api.nvim_get_current_line():match("^[*|/\\_ ]*(%x%x%x%x%x%x%x+)") + if not sha then + return false + end + ---@cast r -nil + require("git.object").open(r, sha, { split = false }) + return true +end + ---@param buf integer local function attach_dispatch(buf) vim.keymap.set("n", "", function() - local r = repo.resolve(buf) - -- Anchor past the leading graph chars (matches the leading sha column, - -- not any hex word that happens to appear later in the subject). - local sha = r - and vim.api - .nvim_get_current_line() - :match("^[*|/\\_ ]*(%x%x%x%x%x%x%x+)") - if sha then - ---@cast r -nil - require("git.object").open(r, sha, { split = false }) - else + if not open_under_cursor(buf) then vim.api.nvim_feedkeys(cr, "n", false) end end, { buffer = buf, silent = true, desc = "Open commit" }) + vim.keymap.set("n", "gd", function() + open_under_cursor(buf) + end, { buffer = buf, silent = true, desc = "Open commit" }) end ---@param worktree string diff --git a/lua/git/object.lua b/lua/git/object.lua index 6fe67f9..7eb1325 100644 --- a/lua/git/object.lua +++ b/lua/git/object.lua @@ -150,6 +150,9 @@ function M.attach_dispatch(buf) vim.api.nvim_feedkeys(cr, "n", false) end end, { buffer = buf, silent = true, desc = "Open file at commit" }) + vim.keymap.set("n", "gd", function() + M.open_under_cursor() + end, { buffer = buf, silent = true, desc = "Open file at commit" }) end ---@param r ow.Git.Repo