Skip to content

Add close key for history and branch view #451

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

Merged
merged 3 commits into from
May 2, 2023
Merged
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
3 changes: 3 additions & 0 deletions lua/neogit/buffers/branch_select_view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function M:open()
kind = "split",
mappings = {
n = {
["q"] = function()
self:close()
end,
["<enter>"] = function(buffer)
local current_line = buffer:get_current_line()
local branch_name = current_line[1]
Expand Down
27 changes: 18 additions & 9 deletions lua/neogit/buffers/git_command_history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,41 @@ local text = Ui.text
local col = Ui.col
local row = Ui.row

local GitCommandHistory = {}
GitCommandHistory.__index = GitCommandHistory
local M = {}

function GitCommandHistory:new(state)
function M:new(state)
local this = {
buffer = nil,
state = state or Git.cli.history,
open = false,
is_open = false,
}

setmetatable(this, self)
setmetatable(this, { __index = M })

return this
end

function GitCommandHistory:show()
if self.open then

function M:close()
self.is_open = false
self.buffer:close()
self.buffer = nil
end

function M:show()
if self.is_open then
return
end
self.is_open = true

self.open = true
self.buffer = Buffer.create {
name = "NeogitGitCommandHistory",
filetype = "NeogitGitCommandHistory",
mappings = {
n = {
["q"] = function()
self:close()
end,
["<tab>"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
local c = stack[#stack]
Expand Down Expand Up @@ -79,4 +88,4 @@ function GitCommandHistory:show()
}
end

return GitCommandHistory
return M
18 changes: 13 additions & 5 deletions lua/neogit/lib/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,20 @@ function Buffer:close(force)
if force == nil then
force = false
end
if self.kind == "tab" then
-- `silent!` as this might throw errors if 'hidden' is disabled.
vim.cmd("silent! 1only")
vim.cmd("try | tabn # | catch /.*/ | tabp | endtry")

if self.kind == "replace" then
vim.api.nvim_buf_delete(self.handle, { force = force })
return
end

if api.nvim_buf_is_valid(self.handle) then
vim.api.nvim_buf_delete(self.handle, { force = force })
local winnr = vim.fn.bufwinnr(self.handle)
if winnr ~= -1 then
local winid = vim.fn.win_getid(winnr)
vim.api.nvim_win_close(winid, force)
else
vim.api.nvim_buf_delete(self.handle, { force = force })
end
end
end

Expand Down Expand Up @@ -242,9 +248,11 @@ function Buffer:add_highlight(line, col_start, col_end, name, ns_id)

vim.api.nvim_buf_add_highlight(self.handle, ns_id, name, line, col_start, col_end)
end

function Buffer:unplace_sign(id)
vim.cmd("sign unplace " .. id)
end

function Buffer:place_sign(line, name, group, id)
-- Sign IDs should be unique within a group, however there's no downside as
-- long as we don't want to uniquely identify the placed sign later. Thus,
Expand Down
5 changes: 2 additions & 3 deletions lua/neogit/popups/help.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local popup = require("neogit.lib.popup")
local status = require("neogit.status")
local GitCommandHistory = require("neogit.buffers.git_command_history")

local M = {}

Expand All @@ -15,7 +14,7 @@ function M.create(env)
:action("P", "Push", function()
require("neogit.popups.push").create()
end)
:action("Z", "Stash", function(_popup)
:action("Z", "Stash", function()
require("neogit.popups.stash").create(env.get_stash())
end)
:action("L", "Log", function()
Expand All @@ -32,7 +31,7 @@ function M.create(env)
require("neogit.popups.branch").create()
end)
:action("$", "Git Command History", function()
GitCommandHistory:new():show()
require("neogit.buffers.git_command_history"):new():show()
end)
:action("<c-r>", "Refresh Status Buffer", function()
status.refresh(true, "user_refresh")
Expand Down