Skip to content

Commit

Permalink
feat: add close keymaps to commit log panel
Browse files Browse the repository at this point in the history
  • Loading branch information
kevintraver committed Apr 4, 2024
1 parent 3dc498c commit d2659c4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lua/diffview/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ M.defaults = {
{ "n", "q", actions.close, { desc = "Close help menu" } },
{ "n", "<esc>", actions.close, { desc = "Close help menu" } },
},
commit_log_panel = {
{ "n", "q", actions.close, { desc = "Close commit log" } },
{ "n", "<esc>", actions.close, { desc = "Close commit log" } },
},
},
}
-- stylua: ignore end
Expand Down
2 changes: 1 addition & 1 deletion lua/diffview/scene/views/diff/diff_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end
function DiffView:post_open()
vim.cmd("redraw")

self.commit_log_panel = CommitLogPanel(self.adapter, {
self.commit_log_panel = CommitLogPanel(self, self.adapter, {
name = fmt("diffview://%s/log/%d/%s", self.adapter.ctx.dir, self.tabpage, "commit_log"),
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function FileHistoryView:init(opt)
end

function FileHistoryView:post_open()
self.commit_log_panel = CommitLogPanel(self.adapter, {
self.commit_log_panel = CommitLogPanel(self, self.adapter, {
name = ("diffview://%s/log/%d/%s"):format(self.adapter.ctx.dir, self.tabpage, "commit_log"),
})

Expand Down
17 changes: 16 additions & 1 deletion lua/diffview/ui/panels/commit_log_panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end

---@param adapter VCSAdapter
---@param opt CommitLogPanelSpec
function CommitLogPanel:init(adapter, opt)
function CommitLogPanel:init(parent, adapter, opt)
self:super({
bufname = opt.name,
config = opt.config or get_user_config().commit_log_panel.win_config,
Expand All @@ -65,6 +65,21 @@ function CommitLogPanel:init(adapter, opt)
vim.bo[self.bufid].bufhidden = "wipe"
end,
})

local conf = get_user_config().keymaps
local default_opt = { silent = true, nowait = true, buffer = self.bufid }

for _, mapping in ipairs(conf.commit_log_panel) do
local map_opt = vim.tbl_extend("force", default_opt, mapping[4] or {}, { buffer = self.bufid })
vim.keymap.set(mapping[1], mapping[2], mapping[3], map_opt)
end

parent.emitter:on("close", function(e)
if self:is_focused() then
self:close()
e:stop_propagation()
end
end)
end

---@param self CommitLogPanel
Expand Down

0 comments on commit d2659c4

Please sign in to comment.