diff --git a/lua/neogit.lua b/lua/neogit.lua index 7be5f8909..3d497a664 100644 --- a/lua/neogit.lua +++ b/lua/neogit.lua @@ -123,4 +123,5 @@ return { close = status.close, setup = setup, complete = complete, + autocmd_group = vim.api.nvim_create_augroup("Neogit", { clear = false }), } diff --git a/lua/neogit/autocmds.lua b/lua/neogit/autocmds.lua index 522489987..9a990b4e9 100644 --- a/lua/neogit/autocmds.lua +++ b/lua/neogit/autocmds.lua @@ -1,11 +1,10 @@ local M = {} local api = vim.api -local group = api.nvim_create_augroup("Neogit", { clear = true }) - local a = require("plenary.async") local status = require("neogit.status") local fs = require("neogit.lib.fs") +local group = require("neogit").autocmd_group function M.setup() api.nvim_create_autocmd({ "BufWritePost", "ShellCmdPost", "VimResume" }, { diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index 04ff05d30..38ed2abcc 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -1,5 +1,9 @@ local M = {} +function M.get_reversed_status_maps() + return vim.tbl_add_reverse_lookup(vim.tbl_deep_extend("force", M.values.mappings.status, {})) +end + M.values = { disable_hint = false, disable_context_highlighting = false, diff --git a/lua/neogit/lib/buffer.lua b/lua/neogit/lib/buffer.lua index b2ee917e7..14461d905 100644 --- a/lua/neogit/lib/buffer.lua +++ b/lua/neogit/lib/buffer.lua @@ -401,8 +401,9 @@ function Buffer.create(config) buffer.ui:render(unpack(config.render(buffer))) end + local neogit_augroup = require("neogit").autocmd_group for event, callback in pairs(config.autocmds or {}) do - api.nvim_create_autocmd(event, { callback = callback, buffer = buffer.handle }) + api.nvim_create_autocmd(event, { callback = callback, buffer = buffer.handle, group = neogit_augroup }) end buffer.mmanager.register() diff --git a/lua/neogit/lib/popup.lua b/lua/neogit/lib/popup.lua index 69a092f6d..2dca4d86e 100644 --- a/lua/neogit/lib/popup.lua +++ b/lua/neogit/lib/popup.lua @@ -574,6 +574,14 @@ function M:show() }, } end, + autocmds = { + ["WinLeave"] = function() + if self.buffer.kind == "floating" then + -- We pcall this because it's possible the window was closed by a command invocation, e.g. "cc" for commits + pcall(self.close, self) + end + end, + }, } end diff --git a/lua/neogit/lib/util.lua b/lua/neogit/lib/util.lua index fe7fb3e5e..ff7f81ea3 100644 --- a/lua/neogit/lib/util.lua +++ b/lua/neogit/lib/util.lua @@ -278,6 +278,10 @@ local function lists_equal(l1, l2) return true end +local function pad_right(s, len) + return s .. string.rep(" ", math.max(len - #s, 0)) +end + return { time = time, time_async = time_async, @@ -307,4 +311,5 @@ return { str_clamp = str_clamp, remove_item_from_table = remove_item_from_table, lists_equal = lists_equal, + pad_right = pad_right, } diff --git a/lua/neogit/popups/help/actions.lua b/lua/neogit/popups/help/actions.lua index 1651802ca..361a9bb29 100644 --- a/lua/neogit/popups/help/actions.lua +++ b/lua/neogit/popups/help/actions.lua @@ -4,9 +4,7 @@ local util = require("neogit.lib.util") local NONE = function() end -- Using deep extend this way creates a copy of the mapping values -local status_mappings = vim.tbl_add_reverse_lookup( - vim.tbl_deep_extend("force", require("neogit.config").values.mappings.status, {}) -) +local status_mappings = require("neogit.config").get_reversed_status_maps() local function present(commands) local presenter = util.map(commands, function(command) diff --git a/lua/neogit/popups/rebase/init.lua b/lua/neogit/popups/rebase/init.lua index b6f2d61b2..73743ec59 100644 --- a/lua/neogit/popups/rebase/init.lua +++ b/lua/neogit/popups/rebase/init.lua @@ -42,7 +42,7 @@ function M.create(commit) :action_if(not in_rebase, "f", "to autosquash") :env({ commit = commit, - highlight = { branch, git.repo.upstream.ref }, + highlight = { branch, git.repo.upstream.ref, base_branch }, bold = { "@{upstream}", "pushRemote" }, }) :build() diff --git a/lua/neogit/process.lua b/lua/neogit/process.lua index 5954c2013..a5c489869 100644 --- a/lua/neogit/process.lua +++ b/lua/neogit/process.lua @@ -66,7 +66,7 @@ local function create_preview_buffer() -- May be called multiple times due to scheduling if preview_buffer then if preview_buffer.buffer then - logger.debug("Preview buffer already exists. Focusing the existing one") + logger.trace("[PROCESS] Preview buffer already exists. Focusing the existing one") preview_buffer.buffer:focus() end return @@ -360,7 +360,7 @@ function Process:spawn(cb) end end - logger.debug("Spawning: " .. vim.inspect(self.cmd)) + logger.trace("[PROCESS] Spawning: " .. vim.inspect(self.cmd)) local job = vim.fn.jobstart(self.cmd, { cwd = self.cwd, env = self.env, diff --git a/lua/neogit/status.lua b/lua/neogit/status.lua index bd7e650c3..ca7db5f77 100644 --- a/lua/neogit/status.lua +++ b/lua/neogit/status.lua @@ -12,6 +12,7 @@ local F = require("neogit.lib.functional") local LineBuffer = require("neogit.lib.line_buffer") local fs = require("neogit.lib.fs") local input = require("neogit.lib.input") +local util = require("neogit.lib.util") local map = require("neogit.lib.util").map local api = vim.api @@ -145,17 +146,28 @@ local function format_mode(mode) return mode end -local function pad_right(s, len) - return s .. string.rep(" ", math.max(len - #s, 0)) -end - local function draw_buffer() M.status_buffer:clear_sign_group("hl") M.status_buffer:clear_sign_group("fold_markers") local output = LineBuffer.new() if not config.values.disable_hint then - output:append("Hint: [] toggle diff | [s]tage | [u]nstage | [x] discard | [c]ommit | [?] more help") + local reversed_status_map = config.get_reversed_status_maps() + + local function hint_label(map_name, hint) + return "[" .. reversed_status_map[map_name] .. "] " .. hint + end + + local hints = { + hint_label("Toggle", "toggle diff"), + hint_label("Stage", "stage"), + hint_label("Unstage", "unstage"), + hint_label("Discard", "discard"), + hint_label("CommitPopup", "commit"), + hint_label("HelpPopup", "help"), + } + + output:append("Hint: " .. table.concat(hints, " | ")) output:append("") end @@ -207,7 +219,7 @@ local function draw_buffer() location.files = {} for _, f in ipairs(data.items) do - local label = pad_right(format_mode(f.mode), max_len) + local label = util.pad_right(format_mode(f.mode), max_len) if label and vim.o.columns < 120 then label = vim.trim(label) end