gui: a page's row in Sidebar pages is dragged by a finger too (chet030714 on X)

v0.1.4296's page order "根本拖不动" on a phone. Reproduced in Chromium
with real touch input (CDP Input.dispatchTouchEvent, 390px, hasTouch,
isMobile): the press on the grip went pointerdown, pointermove,
lostpointercapture, and the drag ended before it began. A finger (and a
pen, where the browser does so) is captured by what it pressed, here the
grip span inside the row; dragRows then takes the capture on the row,
the grip loses it, and its lostpointercapture bubbled to the row's
listener in dragListen, which cancelled the drag. A mouse has no
implicit capture, which is why the mouse test and the desktop app were
fine (mouse drags passed in Chromium and WebKit, 1100px and 390px).

dragListen now cancels only on the handle's own lostpointercapture. The
fix is in the shared listener, so every dragRows/dragCards whose handle
holds a child (the accounts' rows, a model's rows, plugin pages) gets it.
On a coarse pointer the grip is 40px wide instead of 26, a finger's
target. Alt+Up/Down is unchanged. No new motion: the rows' existing
0.16s strong ease-out shift (none under reduced motion) is what a finger
drag shows. The listener's lines were written shorter so app.js stays
under its budget (4 bytes of room left), no raise.

Run:
- nav-pages-order.test.cjs: a finger drag (CDP touch) and a pen drag
  (CDP pointerType pen) on the phone's menu, Chromium; WebKit checks the
  grip shows. 10/10 (Chromium, WebKit x en/zh/zh-TW/ja/de) on mica.
  Red on origin/main 269e54de5's app.js: "a finger dragged Masking up",
  chromium en and zh (2/2). The pen step passes on the old code too
  (Chromium's CDP pen isn't implicitly captured), so it guards nothing
  old, only the path.
- The drag GUI files (account-arrange, agent-grip, codex-model-order,
  drag-rows-shift, gateway-key-arrange, group-arrange, group-member-drag,
  group-member-row-drag, panel-arrange, plugin-page-arrange,
  provider-order, routing-rule-drag, usage-arrange, usage-drag,
  tap-lost-click, tap-inverted, tap-click, search-order, nav-pages-order)
  on mica: 196 pass / 12 fail. The 12 are account-arrange (53 !== 52,
  #6010) and gateway-key-arrange 420px (#6268); both fail the same 12 at
  origin/main 269e54de5's assets.
- go test ./internal/gui/ on mote: ok (TestCoreScriptBudget included).

Not tried: a real phone (iOS Safari, Android Chrome); WebKit touch,
which Playwright can't send; a real pen; the Wails windows.
This commit is contained in:
yetone
2026-11-16 17:03:53 +08:00
parent 91b3af8470
commit 187d067241
4 changed files with 38 additions and 6 deletions
File diff suppressed because one or more lines are too long
+2
View File
@@ -3397,6 +3397,8 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
/* apart: Safari before 15.4 drops a whole selector list with :focus-visible in it */
.nav-pages-menu .pm-item:focus-visible .grip { opacity: 1; }
@media (hover: none) { .nav-pages-menu .grip { opacity: 1; } }
/* a finger gets a grip it can find: 40px wide where the pointer is coarse */
@media (pointer: coarse) { .nav-pages-menu .grip { width: 40px; } }
.nav-pages-menu .pm-fixed .pm-tick { opacity: .4; }
.nav-pages-list.sorting { user-select: none; -webkit-user-select: none; }
.nav-pages-list.sorting > .pm-item { transition: transform .16s cubic-bezier(.23, 1, .32, 1); cursor: grabbing; }
+9 -5
View File
@@ -3079,12 +3079,16 @@ function dragScroll(list) {
: down && y > bounds.bottom - edge ? Math.min(1, (y - bounds.bottom + edge) / edge) : 0;
} };
}
// dragListen: a drag's listeners (letting go saves; Escape, blur, resize cancel)
// dragListen: a drag's listeners (letting go saves; Escape, blur, resize cancel).
// A finger or pen is captured by what it pressed, a grip inside the handle
// too: the handle taking the capture makes that child lose it, and its
// lostpointercapture bubbles up here, so only the handle's own cancels
// (chet030714 on X: a page's row couldn't be dragged on a phone).
function dragListen(handle, move, finish) {
const cancel = (ev) => finish(false, ev);
const on = [[document, "pointermove", move, { passive: false }], [document, "pointerup", (ev) => finish(true, ev)],
[document, "pointercancel", cancel], [handle, "lostpointercapture", cancel], [window, "blur", cancel], [window, "resize", cancel],
[document, "keydown", (ev) => { if (ev.key === "Escape") { ev.preventDefault(); ev.stopImmediatePropagation(); finish(false); } }, true]];
const cancel = (e) => finish(false, e);
const on = [[document, "pointermove", move, { passive: false }], [document, "pointerup", (e) => finish(true, e)],
[document, "pointercancel", cancel], [handle, "lostpointercapture", (e) => e.target == handle && cancel(e)], [window, "blur", cancel], [window, "resize", cancel],
[document, "keydown", (e) => { if (e.key == "Escape") { e.preventDefault(); e.stopImmediatePropagation(); cancel(); } }, true]];
for (const [t, n, f, o] of on) t.addEventListener(n, f, o);
return () => { for (const [t, n, f, o] of on) t.removeEventListener(n, f, o); };
}
@@ -60,6 +60,17 @@ const menuOrder = (page) => page.$$eval(".nav-pages-menu .nav-pages-list .pm-ite
// imported as the page starts
const arranged = (page, want) => page.waitForFunction((w) => [...document.querySelectorAll("#nav > button[data-view]:not([data-plugin-page])")].map((b) => b.dataset.view).join() === w.join(), want);
const kept = (page) => page.evaluate(() => JSON.parse(localStorage.getItem("magpie.navOrder") || "null"));
// drag v's row by its grip onto the row of onto, through send(type, x, y)
async function dragBy(page, v, onto, send, down, moving, up, below = false) {
const g = await page.locator(`.nav-pages-menu [data-v="${v}"] .grip`).boundingBox();
const o = await page.locator(`.nav-pages-menu [data-v="${onto}"]`).boundingBox();
const x = g.x + g.width / 2, y0 = g.y + g.height / 2, y1 = below ? o.y + o.height - 2 : o.y + 2;
await send(down, x, y0);
for (let i = 1; i <= 15; i++) { await send(moving, x, y0 + (y1 - y0) * i / 15); await page.waitForTimeout(16); }
await page.waitForTimeout(80);
await send(up, x, y1);
await page.waitForTimeout(50);
}
const move = (list, v, to) => { const o = list.filter((x) => x !== v); o.splice(to, 0, v); return o; };
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
@@ -132,6 +143,21 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await phone.locator(".nav-pages-pick").tap();
await phone.waitForSelector(".nav-pages-menu .grip");
assert.equal(await phone.locator('.nav-pages-menu [data-v="routing"] .grip').isVisible(), true, "a phone shows the grip");
// a finger drags a row by its grip (chet030714 on X: it wouldn't move
// at all). Playwright can only touch through Chromium's CDP; in WebKit
// the grip being there is what is checked.
if (engine === "chromium") {
const before = await menuOrder(phone);
const cdp = await phone.context().newCDPSession(phone);
const touch = (type, x, y) => cdp.send("Input.dispatchTouchEvent", { type, touchPoints: type === "touchEnd" ? [] : [{ x, y }] });
await dragBy(phone, "masking", before[1], touch, "touchStart", "touchMove", "touchEnd");
assert.deepEqual(await menuOrder(phone), move(before, "masking", 1), "a finger dragged Masking up");
// and a pen
const pen = (type, x, y) => cdp.send("Input.dispatchMouseEvent", { type, x, y, button: "left", buttons: type === "mouseReleased" ? 0 : 1, clickCount: 1, pointerType: "pen" });
const now = await menuOrder(phone);
await dragBy(phone, "masking", now.at(-1), pen, "mousePressed", "mouseMoved", "mouseReleased", true);
assert.deepEqual(await menuOrder(phone), move(now, "masking", now.length - 1), "a pen dragged it to the foot");
}
assert.deepEqual(phone.errors, []);
// a page the kept order doesn't name (new in an update) goes after