Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add close keymaps to commit log panel #482

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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