Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d132c00032 | |||
| 73fa92afc8 |
@@ -66,6 +66,18 @@ vim.api.nvim_create_autocmd({ "BufReadPost" }, {
|
|||||||
command = 'silent! normal! g`"zv',
|
command = 'silent! normal! g`"zv',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("BufWinEnter", {
|
||||||
|
desc = "Reset foldlevel to 0 when entering a diff window."
|
||||||
|
.. " Vim's partial diff-state restoration on buffer re-entry"
|
||||||
|
.. " (e.g. via <C-o>) doesn't re-apply foldlevel=0, so"
|
||||||
|
.. " foldlevelstart leaks through and folds appear open.",
|
||||||
|
callback = function()
|
||||||
|
if vim.wo.diff then
|
||||||
|
vim.wo.foldlevel = 0
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
pattern = { "c" },
|
pattern = { "c" },
|
||||||
callback = function()
|
callback = function()
|
||||||
|
|||||||
+20
-11
@@ -7,23 +7,32 @@ 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
|
||||||
|
---@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
|
---@param buf integer
|
||||||
local function attach_dispatch(buf)
|
local function attach_dispatch(buf)
|
||||||
vim.keymap.set("n", "<CR>", function()
|
vim.keymap.set("n", "<CR>", function()
|
||||||
local r = repo.resolve(buf)
|
if not open_under_cursor(buf) then
|
||||||
-- 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
|
|
||||||
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