feat(git): bind gd to open-under-cursor in log and object views
This commit is contained in:
+16
-7
@@ -8,22 +8,31 @@ local LOG_FORMAT = "%h %ad {%an}%d %s"
|
|||||||
local cr = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
|
local cr = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
|
||||||
|
|
||||||
---@param buf integer
|
---@param buf integer
|
||||||
local function attach_dispatch(buf)
|
---@return boolean opened
|
||||||
vim.keymap.set("n", "<CR>", function()
|
local function open_under_cursor(buf)
|
||||||
local r = repo.resolve(buf)
|
local r = repo.resolve(buf)
|
||||||
-- Anchor past the leading graph chars (matches the leading sha column,
|
-- Anchor past the leading graph chars (matches the leading sha column,
|
||||||
-- not any hex word that happens to appear later in the subject).
|
-- not any hex word that happens to appear later in the subject).
|
||||||
local sha = r
|
local sha = r
|
||||||
and vim.api
|
and vim.api.nvim_get_current_line():match("^[*|/\\_ ]*(%x%x%x%x%x%x%x+)")
|
||||||
.nvim_get_current_line()
|
if not sha then
|
||||||
:match("^[*|/\\_ ]*(%x%x%x%x%x%x%x+)")
|
return false
|
||||||
if sha then
|
end
|
||||||
---@cast r -nil
|
---@cast r -nil
|
||||||
require("git.object").open(r, sha, { split = false })
|
require("git.object").open(r, sha, { split = false })
|
||||||
else
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param buf integer
|
||||||
|
local function attach_dispatch(buf)
|
||||||
|
vim.keymap.set("n", "<CR>", function()
|
||||||
|
if not open_under_cursor(buf) then
|
||||||
vim.api.nvim_feedkeys(cr, "n", false)
|
vim.api.nvim_feedkeys(cr, "n", false)
|
||||||
end
|
end
|
||||||
end, { buffer = buf, silent = true, desc = "Open commit" })
|
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
|
end
|
||||||
|
|
||||||
---@param worktree string
|
---@param worktree string
|
||||||
|
|||||||
@@ -150,6 +150,9 @@ function M.attach_dispatch(buf)
|
|||||||
vim.api.nvim_feedkeys(cr, "n", false)
|
vim.api.nvim_feedkeys(cr, "n", false)
|
||||||
end
|
end
|
||||||
end, { buffer = buf, silent = true, desc = "Open file at commit" })
|
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
|
end
|
||||||
|
|
||||||
---@param r ow.Git.Repo
|
---@param r ow.Git.Repo
|
||||||
|
|||||||
Reference in New Issue
Block a user