Skip to content

Commit

Permalink
Lua: Discard vimade namespaces when switching colorscheme or backgrou…
Browse files Browse the repository at this point in the history
…nd settings. This ensures that links stay in a good state.
  • Loading branch information
TaDaa committed Dec 24, 2024
1 parent a5b0039 commit 8164565
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lua/vimade/fader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ local update = function ()
end
end

if BIT_BAND(GLOBALS.tick_state, GLOBALS.DISCARD_NS) > 0 then
NAMESPACE.discard_all()
end

if current.winid ~= -1 then
WIN_STATE.refresh_active(current.winid)
end
Expand Down Expand Up @@ -93,7 +97,7 @@ M.getInfo = function ()
end

M.redraw = function()
M.tick(BIT_BOR(GLOBALS.RECALCULATE, GLOBALS.CHANGED))
M.tick(BIT_BOR(GLOBALS.RECALCULATE, GLOBALS.DISCARD_NS, GLOBALS.CHANGED))
end

M.animate = function ()
Expand Down
3 changes: 2 additions & 1 deletion lua/vimade/state/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ M.READY = 0
M.ERROR = 1
M.CHANGED = 2
M.RECALCULATE = 4
M.DISCARD_NS = 8
-- some plugins (e.g. Neotree) add the highlights on window/buffer change. When nohlcheck,
-- which prevents rechecking the namespaces for no reason, is enabled we tell the downstream
-- logic to check namespaces on buf/win/tab change.
Expand Down Expand Up @@ -259,7 +260,7 @@ M.refresh = function (override_tick_state)
is_dark = vim.go.background == 'dark',
colorscheme = vim.g.colors_name,
termguicolors = vim.go.termguicolors,
}, M, OTHER, BIT_BOR(M.RECALCULATE, M.CHANGED)))
}, M, OTHER, BIT_BOR(M.RECALCULATE, M.DISCARD_NS, M.CHANGED)))
M.tick_state = BIT_BOR(M.tick_state, check_fields({
'vimade_fade_active',
}, {
Expand Down
11 changes: 10 additions & 1 deletion lua/vimade/state/namespace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ M.clear_winid = function (winid, will_self_reuse)
M.winid_lookup[winid] = nil
if current_win_ns ~= nil then
current_win_ns.windows[winid] = nil

if next(current_win_ns.windows) == nil then
M.key_lookup[current_win_ns.key] = nil
M.vimade_active_ns_lookup[current_win_ns.vimade_ns] = nil
Expand All @@ -39,6 +38,16 @@ M.clear_winid = function (winid, will_self_reuse)
end
end

-- This discards and uncaches all namespaces managed by vimade. This is useful
-- when the namespace reaches an unrecoverable state (e.g. switching between some
-- colorschemes may break the namespace link state).
M.discard_all = function()
for winid, state in pairs(M.winid_lookup) do
M.clear_winid(winid)
end
M.free_ns = {}
end

M.get_replacement = function (win, real_ns, hi_key, skip_create)
local key = hi_key

Expand Down

0 comments on commit 8164565

Please sign in to comment.