Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(pages): report a page selection only once it stops changing

AdityaUmale7140f16cc9b4
diff --git a/shared/app-frame/helper.test.ts b/shared/app-frame/helper.test.ts
index 5e961c7da0..4ab54f9a59 100644
--- a/shared/app-frame/helper.test.ts
+++ b/shared/app-frame/helper.test.ts
@@ -236,6 +236,18 @@ describe("the text the person selects in a bot page", () => {
expect(page.seen.selections).toHaveLength(2);
});
+ it("waits until the person stops changing it, so a selection still being made is not offered", async () => {
+ const page = boot();
+ await expect.poll(() => page.bridge.initialized).toBe(true);
+ for (const text of ["T", "To", "Tot", "Tota", "Total: 42"]) {
+ selectText(page, text);
+ await new Promise((resolve) => setTimeout(resolve, 30));
+ }
+ await expect.poll(() => page.seen.selections.length).toBe(1);
+ await new Promise((resolve) => setTimeout(resolve, 150));
+ expect(page.seen.selections).toEqual([expect.objectContaining({ text: "Total: 42" })]);
+ });
+
it("is never reported from a room's page", async () => {
const page = boot(true, { room: true });
await expect.poll(() => page.bridge.initialized).toBe(true);
diff --git a/shared/app-frame/helper.ts b/shared/app-frame/helper.ts
index e23dec16cb..1281ac8a81 100644
--- a/shared/app-frame/helper.ts
+++ b/shared/app-frame/helper.ts
@@ -177,7 +177,8 @@ const helperSource = (room: boolean) => `(function () {
notify("${APP_SELECTION_METHOD}", { text: text.slice(0, ${APP_SELECTION_CHARS}), left: end.left, bottom: end.bottom });
};
document.addEventListener("selectionchange", function () {
- if (timer === null) timer = setTimeout(report, 100);
+ if (timer !== null) clearTimeout(timer);
+ timer = setTimeout(report, 100);
});
};
var ready = request("ui/initialize", {