Skip to content

Commit

Permalink
Fix lingering winhighlight (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit authored Jan 30, 2025
1 parent 6a1c8c1 commit f0ba99b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lua/winmove/highlight.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
-- TODO: Convert to use nvim_win_set_hl_ns when we have nvim_win_get_hl_ns:
-- https://github.com/neovim/neovim/issues/24309

local highlight = {}

local compat = require("winmove.compat")
Expand All @@ -14,6 +11,7 @@ local api = vim.api
local global_ns_id = 0

-- Window higlights per mode
---@type table<winmove.Mode, string?>
local win_highlights = {
move = nil,
swap = nil,
Expand Down Expand Up @@ -126,9 +124,10 @@ end

---@param win_id integer
---@param mode winmove.Mode
---@return boolean
function highlight.has_highlight(win_id, mode)
if not api.nvim_win_is_valid(win_id) then
return
return false
end

return vim.wo[win_id].winhighlight == win_highlights[mode]
Expand Down
20 changes: 20 additions & 0 deletions lua/winmove/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -800,4 +800,24 @@ function winmove.configure(user_config)
config.configure(user_config)
end

local function fix_lingering_winhighlight()
-- See https://github.com/neovim/neovim/discussions/32163 for details
api.nvim_create_autocmd("BufWinEnter", {
callback = function()
local win_id = api.nvim_get_current_win()
local has_winmove_hl = highlight.has_highlight(win_id, winmove.Mode.Move)
or highlight.has_highlight(win_id, winmove.Mode.Swap)
or highlight.has_highlight(win_id, winmove.Mode.Resize)

if has_winmove_hl then
vim.wo[win_id].winhighlight = ""
end
end,
group = augroup,
desc = "Fixes lingering winhighlight for winmove modes",
})
end

fix_lingering_winhighlight()

return winmove

0 comments on commit f0ba99b

Please sign in to comment.