From 0ad78240b5658c65d0c7d5bd08c1bd1099b79dd3 Mon Sep 17 00:00:00 2001 From: Fabian-programmer Date: Sat, 25 Feb 2023 11:15:51 +0100 Subject: [PATCH 1/3] chore: close buffer by its underlying window --- lua/neogit/lib/buffer.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lua/neogit/lib/buffer.lua b/lua/neogit/lib/buffer.lua index 1b24536a7..d3c06b0e3 100644 --- a/lua/neogit/lib/buffer.lua +++ b/lua/neogit/lib/buffer.lua @@ -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 @@ -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, From 3a00bc5c9a772ddbbd65b204a7ac0568d2730189 Mon Sep 17 00:00:00 2001 From: Fabian-programmer Date: Sat, 25 Feb 2023 17:12:54 +0100 Subject: [PATCH 2/3] Add close key to git command history --- lua/neogit/buffers/git_command_history.lua | 27 ++++++++++++++-------- lua/neogit/popups/help.lua | 5 ++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lua/neogit/buffers/git_command_history.lua b/lua/neogit/buffers/git_command_history.lua index 9484ff158..1c851cb1b 100644 --- a/lua/neogit/buffers/git_command_history.lua +++ b/lua/neogit/buffers/git_command_history.lua @@ -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, [""] = function() local stack = self.buffer.ui:get_component_stack_under_cursor() local c = stack[#stack] @@ -79,4 +88,4 @@ function GitCommandHistory:show() } end -return GitCommandHistory +return M diff --git a/lua/neogit/popups/help.lua b/lua/neogit/popups/help.lua index 2cfa1c58f..100a59359 100644 --- a/lua/neogit/popups/help.lua +++ b/lua/neogit/popups/help.lua @@ -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 = {} @@ -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() @@ -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("", "Refresh Status Buffer", function() status.refresh(true, "user_refresh") From 37e182f51e5b524ccd291bb3c71c51193ce24253 Mon Sep 17 00:00:00 2001 From: Fabian-programmer Date: Sat, 25 Feb 2023 17:22:31 +0100 Subject: [PATCH 3/3] Add close for branch select view --- lua/neogit/buffers/branch_select_view/init.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/neogit/buffers/branch_select_view/init.lua b/lua/neogit/buffers/branch_select_view/init.lua index ab7fdd8b6..67d6b6e5a 100644 --- a/lua/neogit/buffers/branch_select_view/init.lua +++ b/lua/neogit/buffers/branch_select_view/init.lua @@ -37,6 +37,9 @@ function M:open() kind = "split", mappings = { n = { + ["q"] = function() + self:close() + end, [""] = function(buffer) local current_line = buffer:get_current_line() local branch_name = current_line[1]