fix(git): stop the blame statuscolumn leaking into new windows

This commit is contained in:
2026-05-26 14:02:37 +02:00
parent 872431be3c
commit d81cf95b48
2 changed files with 52 additions and 9 deletions
+26 -9
View File
@@ -521,9 +521,21 @@ end
---@type table<integer, string>
local saved_statuscolumn = {}
---Reconcile every window's `'statuscolumn'` with the overlay state: a
---window showing an overlay buffer gets the blame statuscolumn, and its
---previous value is saved so it can be restored on toggle-off.
---Set a window's `'statuscolumn'` with `scope = "local"`, so the global
---value stays clean and splits and new windows do not inherit the gutter.
---@param win integer
---@param value string
local function set_statuscolumn(win, value)
vim.api.nvim_set_option_value(
"statuscolumn",
value,
{ win = win, scope = "local" }
)
end
---Reconcile every window's `'statuscolumn'` with the overlay state.
---Overlay windows get the blame statuscolumn, and a window that has it
---but should not (a split inherits window options) is restored.
local function refresh_overlay_columns()
for win in pairs(saved_statuscolumn) do
if not vim.api.nvim_win_is_valid(win) then
@@ -533,11 +545,16 @@ local function refresh_overlay_columns()
for _, win in ipairs(vim.api.nvim_list_wins()) do
local state = states[vim.api.nvim_win_get_buf(win)]
local on = state ~= nil and state.overlay
if on and saved_statuscolumn[win] == nil then
saved_statuscolumn[win] = vim.wo[win].statuscolumn
vim.wo[win].statuscolumn = BLAME_EXPR .. native_items(win)
elseif not on and saved_statuscolumn[win] ~= nil then
vim.wo[win].statuscolumn = saved_statuscolumn[win]
local has_blame = vim.startswith(vim.wo[win].statuscolumn, BLAME_EXPR)
if on and not has_blame then
saved_statuscolumn[win] = saved_statuscolumn[win]
or vim.wo[win].statuscolumn
set_statuscolumn(win, BLAME_EXPR .. native_items(win))
elseif not on and has_blame then
set_statuscolumn(
win,
saved_statuscolumn[win] or vim.go.statuscolumn
)
saved_statuscolumn[win] = nil
end
end
@@ -560,7 +577,7 @@ local function render(buf)
build_blame_text(state, win)
built = true
end
vim.wo[win].statuscolumn = BLAME_EXPR .. native_items(win)
set_statuscolumn(win, BLAME_EXPR .. native_items(win))
end
end
end