diff --git a/main.lua b/main.lua index bbe44f54..f8dd9b74 100644 --- a/main.lua +++ b/main.lua @@ -406,6 +406,7 @@ end function love.focus(f) if editorMode or TouchEditor then return end if Importer then + require("src.core.Input"):reset() if Importer.focus then Importer:focus(f) end return end @@ -415,7 +416,10 @@ end -- v is true when the window becomes visible again, false on minimize. function love.visible(v) if editorMode or TouchEditor then return end - if Importer then return end + if Importer then + require("src.core.Input"):reset() + return + end Game:visible(v) end diff --git a/tests/engine/input_focus_reset_test.lua b/tests/engine/input_focus_reset_test.lua new file mode 100644 index 00000000..d403615f --- /dev/null +++ b/tests/engine/input_focus_reset_test.lua @@ -0,0 +1,24 @@ +-- Focus / visibility loss clears held directions (SWNX-18). +package.path = "./?.lua;./?/init.lua;" .. package.path +if not _G.love then _G.love = require("tests.love_stub") end + +local T = require("tests.harness") +local check = T.check + +local Input = require("src.core.Input") +local Game = require("src.core.Game") + +Input:init() +Input:keypressed("left") +Input:step() +check(Input:isDown("left"), "left held before focus loss") + +Game:focus(false) +check(not Input:isDown("left"), "focus loss clears held direction") + +Input:keypressed("up") +Input:step() +Game:visible(false) +check(not Input:isDown("up"), "visibility loss clears held direction") + +T.finish()