diff --git a/api/ui.js b/api/ui.js index 4d2268e1..66464862 100644 --- a/api/ui.js +++ b/api/ui.js @@ -731,12 +731,17 @@ export const flockUI = { }); }; - const timeoutId = setTimeout(fadeOut, safeDuration * 1000); + let timeoutId = null; + if (safeDuration > 0) { + timeoutId = setTimeout(fadeOut, safeDuration * 1000); + } flock.abortController.signal.addEventListener( "abort", () => { - clearTimeout(timeoutId); + if (timeoutId !== null) { + clearTimeout(timeoutId); + } if (flock.stackPanel) { flock.stackPanel.removeControl(bg); bg.dispose(); diff --git a/tests/printtext.test.js b/tests/printtext.test.js index 29c758d2..aaff1bcc 100644 --- a/tests/printtext.test.js +++ b/tests/printtext.test.js @@ -64,5 +64,15 @@ export function runPrintTextTests(flock) { done(); }, 3000); }); + + it("should keep the control when duration is 0", function (done) { + this.timeout(2000); + flock.printText({ text: "Persist", duration: 0 }); + setTimeout(() => { + const bg = advancedTexture.getControlByName("textBackground"); + expect(bg).to.exist; + done(); + }, 250); + }); }); }