gui: a tap that slides a few pixels is a click, not a drag (refeccd)
A trackpad's tap-to-click presses and lets go within tens of ms and the pointer can slide a few pixels between. dragRows and dragCards lifted the row after 4px and marked the handle dragged, so the click that followed was swallowed: an agent row's logo, a provider row, a usage card took a second tap. A press let go under 300ms and under 12px from where it came down now sets nothing down and lets the click through (tapLike). A real drag, held or long, still moves the row. Reported by refeccd (Discord #feedback, 2026-11-03). Run at the pushed head (mote, node --test, Playwright chromium + webkit): tap-click.test.cjs (new; en/zh, window/panel, slid 0/5/9px; 26 ok), and account-arrange, agent-grip, drag-rows-shift, fold-show-grip, gateway-key-arrange, grip-inset, group-arrange, group-member-drag, list-sort, panel-arrange, usage-arrange, click-scroll: ok. Broken by hand: with the old app.js tap-click is 18 of 26 red (every slid 5px and 9px case, both engines); the 0px case passes on both. routing-rule-drag chromium is red on the old app.js too (known: #3789, #5088), not from this. Not run: the whole GUI suite (another session's was running on mote), a real trackpad tap (can't be done from a test), and hover-revealed controls that shift under a tap, none found to be the cause.
This commit is contained in:
@@ -3119,6 +3119,11 @@ function dragListen(handle, move, finish) {
|
||||
return () => { for (const [t, n, f, o] of on) t.removeEventListener(n, f, o); };
|
||||
}
|
||||
|
||||
// A tap-to-click on a trackpad can slide a few pixels between the press and
|
||||
// the lift. A press let go within 300ms and under 12px from where it came down
|
||||
// is a click, not a drag, though it crossed the 4px that lifts a row.
|
||||
const tapLike = (t0, x0, y0, ev) => ev?.type === "pointerup" && performance.now() - t0 < 300 && Math.hypot(ev.clientX - x0, ev.clientY - y0) < 12;
|
||||
|
||||
// Shared pointer sorter: transforms each frame, one commit on release. Rows are
|
||||
// placed each frame by the list's top, as what's above it changes (yuancjun)
|
||||
function dragRows(e, handle, row, list, rows, commit, start = () => {}, idle = () => {}) {
|
||||
@@ -3129,7 +3134,7 @@ function dragRows(e, handle, row, list, rows, commit, start = () => {}, idle = (
|
||||
const lift = rows[0].getBoundingClientRect().top - base() - rows[0].offsetTop, grab = e.clientY - row.getBoundingClientRect().top;
|
||||
const { scroll, speedAt } = dragScroll(list);
|
||||
let dragging = false, ended = false, to = from, y = e.clientY, frame = 0, lastTime = 0;
|
||||
const y0 = y, pointer = e.pointerId;
|
||||
const y0 = y, x0 = e.clientX, t0 = performance.now(), pointer = e.pointerId;
|
||||
const paint = (time) => {
|
||||
frame = 0;
|
||||
if (!rows.every((r) => r.isConnected)) return finish(false);
|
||||
@@ -3177,6 +3182,7 @@ function dragRows(e, handle, row, list, rows, commit, start = () => {}, idle = (
|
||||
};
|
||||
const finish = (save, ev) => {
|
||||
if (ended || (ev?.pointerId != null && ev.pointerId !== pointer)) return;
|
||||
if (save && dragging && tapLike(t0, x0, y0, ev)) { save = false; delete handle.dataset.dragged; }
|
||||
if (save && dragging && ev) {
|
||||
y = ev.clientY;
|
||||
cancelAnimationFrame(frame);
|
||||
@@ -3192,7 +3198,8 @@ function dragRows(e, handle, row, list, rows, commit, start = () => {}, idle = (
|
||||
rows.forEach((r) => { r.style.transform = ""; });
|
||||
if (save && dragging && to !== from) commit(to);
|
||||
idle();
|
||||
// The click dispatched after pointerup must not rename, toggle or remove.
|
||||
// The click dispatched after pointerup must not rename, toggle or remove
|
||||
// (a tap-like press lets it through).
|
||||
setTimeout(() => delete handle.dataset.dragged, 0);
|
||||
};
|
||||
const off = dragListen(handle, move, finish);
|
||||
@@ -3209,7 +3216,7 @@ function dragCards(e, handle, card, list, cards, commit, idle = () => {}) {
|
||||
const rects = cards.map((c) => c.getBoundingClientRect());
|
||||
const { scroll, scroll0, speedAt } = dragScroll(list);
|
||||
let dragging = false, ended = false, to = from, x = e.clientX, y = e.clientY, frame = 0, lastTime = 0;
|
||||
const x0 = x, y0 = y, pointer = e.pointerId;
|
||||
const x0 = x, y0 = y, t0 = performance.now(), pointer = e.pointerId;
|
||||
const r0 = rects[from];
|
||||
const paint = (time) => {
|
||||
frame = 0;
|
||||
@@ -3253,6 +3260,7 @@ function dragCards(e, handle, card, list, cards, commit, idle = () => {}) {
|
||||
};
|
||||
const finish = (save, ev) => {
|
||||
if (ended || (ev?.pointerId != null && ev.pointerId !== pointer)) return;
|
||||
if (save && dragging && tapLike(t0, x0, y0, ev)) { save = false; delete handle.dataset.dragged; }
|
||||
if (save && dragging && ev) {
|
||||
x = ev.clientX;
|
||||
y = ev.clientY;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A trackpad's tap-to-click (refeccd, Discord #feedback): the press and the lift
|
||||
// come within a few tens of milliseconds and the pointer can slide a few pixels
|
||||
// between them, with no hover before. A row's logo handle began a drag after 4px
|
||||
// and swallowed the click that followed, so the tap opened nothing and the
|
||||
// reader tapped again. A press let go quickly and close to where it came down
|
||||
// is a click; a real drag still moves the row. MAGPIE_ASSETS selects an older
|
||||
// asset directory for a failing comparison. The real trackpad can't be driven
|
||||
// from a test. Chromium and WebKit, English and Chinese; 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 = process.env.MAGPIE_ASSETS || path.resolve(__dirname, "../assets");
|
||||
|
||||
function fixture(lang) {
|
||||
const state = { agents: ["alpha", "beta", "gamma"].map((id) => ({ id, name: id, icon: "generic", path: "/fixture/" + id, fields: [] })), profiles: [], settings: { lang, theme: "light", guideHidden: true } }; // the Get started card put away: these rows are the page, the test reads where they sit
|
||||
const posted = [];
|
||||
const route = async (route) => {
|
||||
const request = route.request(), url = new URL(request.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/agents/arrange") {
|
||||
const body = request.postDataJSON();
|
||||
posted.push(body);
|
||||
Object.assign(state.settings, { agentOrder: body.order, agentsHidden: body.hidden, agentsShown: body.shown });
|
||||
return json(state.settings);
|
||||
}
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
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 });
|
||||
};
|
||||
return { state, posted, route };
|
||||
}
|
||||
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": a tap that slides a few pixels still clicks an agent row's handle", { timeout: 120000 }, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const errors = [];
|
||||
t.after(async () => { if (errors.length) console.log(errors); await browser.close(); });
|
||||
for (const lang of ["en", "zh"]) for (const mode of ["window", "panel"]) for (const slide of [0, 5, 9]) {
|
||||
await t.test(`${lang}, ${mode}, slid ${slide}px`, async () => {
|
||||
const ctx = await browser.newContext({ viewport: mode === "panel" ? { width: 380, height: 560 } : { width: 1000, height: 640 }, reducedMotion: "reduce" });
|
||||
const page = await ctx.newPage(), f = fixture(lang);
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", f.route);
|
||||
await page.goto(`http://magpie.test/?view=agents&mode=${mode}`);
|
||||
await page.locator("#agents > .row.agent").nth(2).waitFor();
|
||||
await page.mouse.move(1, 1);
|
||||
const box = await page.locator("#agents > .row.agent").nth(1).locator(".ag-handle").boundingBox();
|
||||
const x = box.x + box.width / 2, y = box.y + box.height / 2 - slide / 2;
|
||||
// no hover before: the pointer comes, presses, slides, lets go at once
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.down();
|
||||
if (slide) await page.mouse.move(x, y + slide);
|
||||
await page.mouse.up();
|
||||
await page.getByRole("menuitem").first().waitFor();
|
||||
assert.deepEqual(f.posted, [], "a tap moved a row");
|
||||
assert.equal(await page.locator("#agents > .row.dragging").count(), 0);
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// a drag the length of a row is still a drag
|
||||
const before = await page.locator("#agents > .row.agent").evaluateAll((rs) => rs.map((r) => r.dataset.id));
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.down();
|
||||
await page.waitForTimeout(350);
|
||||
await page.mouse.move(x, y + box.height * 2.2, { steps: 12 });
|
||||
await page.mouse.up();
|
||||
await page.waitForFunction(() => document.querySelector("#agents > .row.dragging") === null);
|
||||
assert.equal(f.posted.length, 1, "a drag past the next row moved nothing");
|
||||
assert.notDeepEqual(f.posted[0].order.slice(0, 3), before);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user