gui: a tap that slides off its Form | JSON option still picks it (refeccd)

A trackpad's tap lifts a few pixels from where it came down. On the small
options of a segmented control (Form | JSON in the MCP server editor) the
lift can land off the option, so the browser clicks neither it nor the
option it came down on: the press shows (the option shrinks) and nothing is
picked, and the next tap, lifted in place, works. segsPress already clicked
the same option again when a redraw replaced it between down and up; it now
does so too when the option is still there but the press was let go off it,
within tapLike's bounds (under 300ms, under 12px). A press dragged farther,
or held longer, is still no pick, as for any button. Every segs control
(the same helper) takes it, in the editors, Settings and the lists.

Test: library-mcp-first-click presses near the top of the option, slides 8px
up, off the switch, lets go inside 300ms, both ways, in en zh zh-TW ja de,
Chromium and WebKit, at 1100 (desktop) and 390 (web). Red on the old code
(12 of 22: every 1100 case in both engines), green with the fix (22 of 22),
run through mote-run.
Not tried: the reporter's own trackpad and video (not seen); the whole GUI
suite is run before the push, see the push record.
This commit is contained in:
yetone
2026-11-04 02:26:08 +08:00
parent 12d4825afa
commit c360d9d30d
2 changed files with 112 additions and 6 deletions
+17 -6
View File
@@ -6822,8 +6822,9 @@ function segsPlace(box) {
// on a new button. Down and up were on two buttons, so the browser sent the
// click to neither and nothing was picked. Let go on the same option of the
// same control, the new one is clicked; let go anywhere else (dragged off
// to another option), nothing is, as for any button. A tap is left to the
// browser, which clicks what is under the finger as it lifts.
// to another option), nothing is, as for any button. A touch tap is left to
// the browser, which clicks what is under the finger as it lifts; a mouse or
// trackpad tap that slid off its option within tapLike's bounds still picks it.
let segsPress = null;
const optAt = (b) => [...b.parentElement.querySelectorAll(":scope > .opt")].indexOf(b);
// the same control is at the same place, among as many of its kind, in rows
@@ -6838,15 +6839,25 @@ function segsWho(box) {
}
addEventListener("pointerdown", (e) => {
const b = e.isPrimary && e.button === 0 && e.pointerType !== "touch" && e.target.closest?.(".segs > .opt");
segsPress = b ? { b, who: segsWho(b.parentElement), i: optAt(b) } : null;
segsPress = b ? { b, who: segsWho(b.parentElement), i: optAt(b), t: performance.now(), x: e.clientX, y: e.clientY } : null;
}, true);
addEventListener("pointercancel", () => { segsPress = null; }, true);
addEventListener("pointerup", (e) => {
const p = segsPress;
segsPress = null;
if (!p?.who || p.b.isConnected || !e.isPrimary) return;
const b = document.elementFromPoint(e.clientX, e.clientY)?.closest(".segs > .opt");
if (!b || segsWho(b.parentElement) !== p.who || optAt(b) !== p.i) return;
if (!p?.who || !e.isPrimary) return;
let b;
if (p.b.isConnected) {
// a tap that slid off its option (a trackpad's tap lifts a few pixels
// from where it came down, refeccd's first press of Form | JSON): the
// browser clicks neither, or their common holder. A tap is the press
// let go soon and near, as tapLike has it; a drag off it is not.
if (p.b.contains(e.target) || !tapLike(p.t, p.x, p.y, e)) return;
b = p.b;
} else {
b = document.elementFromPoint(e.clientX, e.clientY)?.closest(".segs > .opt");
if (!b || segsWho(b.parentElement) !== p.who || optAt(b) !== p.i) return;
}
// after the browser's own click, should one come to it after all
let clicked = false;
const seen = (c) => { if (b.contains(c.target)) clicked = true; };
@@ -0,0 +1,95 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// refeccd on Discord: Library > MCP servers > magpie-web-search > Edit, the
// Form | JSON switch: the first click changed the text size but not the
// view; it took a second click. A trackpad's tap lifts a few pixels from
// where it came down: here a press near the top of the option that slides 8px
// up, off the switch, in under 300ms. The view must change on the first one,
// both ways, in every language, in Chromium and WebKit, at 1100 and 390
// wide. No backend: the API is faked.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const { I18N } = require("./strings.cjs").strings();
const tr = (lang, s) => (lang === "en" ? s : I18N[lang][s]) || s;
const HOME = "/Users/rf";
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
function server(lang, web) {
const lib = {
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
agents: ["claude:Claude Code","codex:Codex","gemini:Gemini CLI","cursor:Cursor","opencode:OpenCode","kimi:Kimi Code","droid:Droid","amp:Amp","qwen:Qwen Code","crush:Crush","pi:Pi","zed:Zed","trae:Trae","iflow:iFlow","goose:Goose","cline:Cline","roo:Roo","kilo:Kilo","aider:Aider","warp:Warp"].map((x) => agent(...x.split(":"))), mcpHub: true, hubPath: "/mcp",
instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [],
servers: [{ name: "magpie-web-search", transport: "stdio", command: "/Applications/magpie.app/Contents/MacOS/magpie", args: ["mcp", "search"], env: {}, icon: "https://usemagpie.ai/favicon.png", agents: ["claude", "codex", "gemini"] }],
};
return async (route) => {
const req = route.request(), url = new URL(req.url());
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web}};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light" } } });
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
if (url.pathname === "/api/library") return route.fulfill({ json: lib });
if (url.pathname === "/api/library/mcp/check") return route.fulfill({ json: { servers: {} } });
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} });
if (url.hostname === "usemagpie.ai") {
return route.fulfill({ body: await fs.readFile(path.join(assets, "favicon.png")).catch(() => Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==", "base64")), contentType: "image/png" });
}
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": the Form | JSON switch takes the first press", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
t.after(() => browser.close());
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1100, 390]) {
await t.test(`${lang} ${width}`, async () => {
const w = (s) => tr(lang, s);
const ctx = await browser.newContext({ viewport: { width, height: 800 } });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "mcp"); } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
await page.route("**/*", server(lang, width < 600));
await page.goto("http://magpie.test/");
await page.locator('button[data-view="library"]').click();
const ed = page.locator("#modal .lib-editor");
await page.locator("#view-library .lib-server .name", { hasText: "magpie-web-search" }).click();
await ed.waitFor();
await page.waitForTimeout(600); // the dialog has stopped growing in
const pick = (name) => ed.locator(".lib-viewpick .opt", { hasText: new RegExp("^" + name + "$") });
// a press like a trackpad tap: down, a slide of a few px, up soon
const press = async (loc, slide) => {
const b = await loc.boundingBox();
const x = b.x + b.width / 2, y = b.y + 3;
await page.mouse.move(x, y);
await page.mouse.down();
await page.waitForTimeout(60);
if (slide) await page.mouse.move(x, y - slide);
await page.waitForTimeout(40);
await page.mouse.up();
};
for (const slide of [0, 8]) {
await press(pick("JSON"), slide);
await ed.locator("textarea.lib-json").waitFor({ timeout: 1500 });
assert.equal(await pick("JSON").getAttribute("aria-pressed"), "true", "JSON is picked at the first press, slide " + slide);
await press(pick(w("Form")), slide);
await ed.locator("textarea.lib-json").waitFor({ state: "detached", timeout: 1500 });
assert.equal(await pick(w("Form")).getAttribute("aria-pressed"), "true", "Form is picked at the first press, slide " + slide);
}
await ctx.close();
});
}
}
});
}