diff --git a/internal/gui/assets/routing.js b/internal/gui/assets/routing.js index 1a2bd950c..168c09544 100644 --- a/internal/gui/assets/routing.js +++ b/internal/gui/assets/routing.js @@ -1471,7 +1471,10 @@ const on = r.order.filter((x) => !x.fallback).length; const pool = !g && f ? poolOf(f.provider) : null; const lone = !g && on <= 1 && !pool; - chip.textContent = t(m[0]); + // the head is told again every second: a chip whose text node is + // swapped while it is pressed gets no click in WebKit (#2151), so + // only what changed is written + setText(chip, t(m[0])); chip.hidden = lone; goTo(chip, g ? "group:" + g.id : pool ? "pool:" + f.provider : "", g ? g.name : f?.name || r.provider); hubText(); @@ -1484,12 +1487,13 @@ // goTo makes what names a routing a way to where it is set: a provider's // own under Several accounts or keys, a group's its card function goTo(e, go, name) { - e.dataset.go = go; e.classList.toggle("rt-go", !!go); if (go) { - e.tabIndex = 0; - e.setAttribute("role", "button"); - e.title = t("Change how {name} routes", { name }); + const title = t("Change how {name} routes", { name }); + if (e.dataset.go !== go) e.dataset.go = go; + if (e.tabIndex !== 0) e.tabIndex = 0; + if (e.getAttribute("role") !== "button") e.setAttribute("role", "button"); + if (e.title !== title) e.title = title; } else for (const a of ["data-go", "tabindex", "role", "title"]) e.removeAttribute(a); } function goRouting(e, go) { @@ -3209,7 +3213,7 @@ } } - function hubText() { hubSub.textContent = (providers?.gateway?.url || "").replace(/^https?:\/\//, "") || t("gateway"); } + function hubText() { setText(hubSub, (providers?.gateway?.url || "").replace(/^https?:\/\//, "") || t("gateway")); } // labels in the page's language, and again when it changes function words() { diff --git a/internal/gui/tests/routing-mode-goes.test.cjs b/internal/gui/tests/routing-mode-goes.test.cjs index 90937e6cd..41da04c7e 100644 --- a/internal/gui/tests/routing-mode-goes.test.cjs +++ b/internal/gui/tests/routing-mode-goes.test.cjs @@ -74,6 +74,12 @@ async function open(engine, lang, scene, width, t) { page.setDefaultTimeout(5000); const errors = []; page.on("pageerror", (error) => errors.push(error.message)); + // counts the routing view's once-a-second redraws, to hold a press over one + await page.addInitScript(() => { + const every = window.setInterval; + window.__redraws = 0; + window.setInterval = (f, ms, ...a) => every(typeof f === "function" && String(f).includes("renderActs") ? (...x) => { f(...x); window.__redraws++; } : f, ms, ...a); + }); await page.route("**/*", serve(lang, scene)); await page.goto("http://magpie.test/?view=routing"); const req = page.locator(".rt-req").first(); @@ -130,6 +136,20 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await page.evaluate(() => document.activeElement?.classList.contains("on")), true); assert.equal((await page.evaluate(() => document.activeElement.textContent)).trim(), smart[lang]); + // a press held over the head's redraw is still a click (#2151): the + // chip is not written over under the pointer, which WebKit takes + // for a press that never ends where it began + await view.evaluate((v) => { v.scrollTop = 0; }); + await pool.evaluate((p) => p.classList.remove("rt-found")); + const box = await chip.boundingBox(); + await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); + await page.mouse.down(); + const drawn = await page.evaluate(() => window.__redraws); + await page.waitForFunction((n) => window.__redraws > n, drawn, { polling: 50 }); + await page.mouse.up(); + await page.waitForFunction(() => document.querySelector('.rt-pool[data-provider="relay"]')?.classList.contains("rt-found")); + assert.equal(await inView(), true); + // the keyboard does the same from the top await view.evaluate((v) => { v.scrollTop = 0; }); await chip.focus();