Skip to content

Commit

Permalink
Test auto-quiting mode for events
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit committed Feb 4, 2024
1 parent c385441 commit bce6e94
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lua/winmove/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,18 @@ local function create_mode_autocmds(mode, source_win_id)
desc = "Remove highlighting from any new window because the winhighlight option can leak into other windows",
})
)

table.insert(
autocmds,
api.nvim_create_autocmd("InsertEnter", {
callback = function()
stop_mode(mode)
return true
end,
group = augroup,
desc = "Quits " .. mode .. " when entering insert mode",
})
)
end

---@param mode winmove.Mode
Expand Down
28 changes: 28 additions & 0 deletions tests/auto_quit_modes_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
local winmove = require("winmove")
local vader = require("winmove.util.vader")

local given = vader.given

describe("auto-quit mode", function()
it("quits current mode when entering a new window", function()
given("", function()
vim.cmd.vnew()
winmove.start_mode(winmove.mode.Move)
assert.are.same(winmove.current_mode(), winmove.mode.Move)

vim.cmd.new()
assert.are.same(winmove.current_mode(), nil)
end)
end)

it("quits current mode when entering insert mode", function()
given("", function()
vim.cmd.vnew()
winmove.start_mode(winmove.mode.Move)
assert.are.same(winmove.current_mode(), winmove.mode.Move)

vim.cmd.norm([[i]])
assert.are.same(winmove.current_mode(), nil)
end)
end)
end)
2 changes: 1 addition & 1 deletion tests/no_win_events_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("no window events", function()

it("does not trigger any window events when moving", function()
given("", function()
vim.cmd("belowright vnew")
vim.cmd.vnew()

-- Set up autocmds *after* splitting
for _, event in ipairs(events) do
Expand Down

0 comments on commit bce6e94

Please sign in to comment.