From 5f0681216bc7094158432987f5d719ded25dbb99 Mon Sep 17 00:00:00 2001 From: MisanthropicBit Date: Wed, 20 Nov 2024 20:20:25 +0100 Subject: [PATCH] Fix highlighting when swapping windows on error (#20) --- lua/winmove/swap.lua | 2 ++ tests/swap_window_spec.lua | 1 + 2 files changed, 3 insertions(+) diff --git a/lua/winmove/swap.lua b/lua/winmove/swap.lua index 6daebe7..641be44 100644 --- a/lua/winmove/swap.lua +++ b/lua/winmove/swap.lua @@ -43,10 +43,12 @@ function swap.swap_window(win_id) end if not vim.api.nvim_win_is_valid(selected_window) then + highlight.unhighlight_window(selected_window) selected_window = nil message.error("Previously selected window is not valid anymore") return elseif win_id == selected_window then + highlight.unhighlight_window(selected_window) selected_window = nil message.error("Cannot swap selected window with itself") return diff --git a/tests/swap_window_spec.lua b/tests/swap_window_spec.lua index 8c14cd0..3ade9e5 100644 --- a/tests/swap_window_spec.lua +++ b/tests/swap_window_spec.lua @@ -201,6 +201,7 @@ describe("swap window", function() .called_with("[winmove.nvim]: Cannot swap selected window with itself", vim.log.levels.ERROR) assert.matches_winlayout(vim.fn.winlayout(), { "leaf", main_win_id }) + assert.are.same(vim.wo[main_win_id].winhighlight, "") ---@diagnostic disable-next-line: undefined-field vim.notify:revert()