Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gui: a trackpad's coast after the lift is the reader's scroll, no longer put back (issenn on Discord)
yetone1b039a3c7247
diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.mdindex 9fab1f9b9..24e9f2933 100644--- a/docs/subsystems/gui-shell.md+++ b/docs/subsystems/gui-shell.md@@ -375,7 +375,7 @@ covers it in both engines, every language and a narrow window.- Settings' Search APIs add row has a base URL field under the key for every API (#1580): the vendor's own address is its placeholder, picking an API already added fills in its saved URL so a new key alone keeps it, and Add with no key changes only the URL. See [a search API's base URL](gateway-routing.md#a-search-apis-base-url), [`renderSearch`](../../internal/gui/assets/app.js) and `search-api.test.cjs`.- Every user-visible string has zh, zh-TW, ja and de translations with the same placeholders. `gui-zh-tw.test.cjs`, `gui-ja.test.cjs` and `gui-de.test.cjs` fail on a missing one; `gui-zh-tw.test.cjs` also fails on a zh-TW string with a Simplified character left in it.- A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this. A click is taken where the reader left the view: a scroll not theirs made just before it, whose scroll event the browser sends only at the next frame, after the click, is put back first (`backToReader` in the click guard, #1554). What was clicked is held where it was (`hold`); a view at its top when clicked stays at its top, and what comes in above the control moves it down instead (#2134, `update-auto.test.cjs`), as long as it moves less than half its own height and so stays under the pointer. Anything larger above it, as the stage a day picked on Routing brings in above the bar, is scrolled past, and the control stays where it was clicked (`routing-days-fit.test.cjs`, `routing-failed-open.test.cjs`).-- A scroll not the reader's is put back, so every way the reader scrolls has to count as theirs: the wheel, a touch and its fling, the keys, a drag, the scrollbar's own drag (`barDrag`, #1089) and the middle button's autoscroll (`panning`, 多喝热水 on Discord). Chromium and WebView2 give the autoscroll a press of button 1 and then no event of the reader's while it scrolls; from that press the view follows it till Chromium ends it, on the next press (which reaches the page only as a pointerup), a key (a keyup), or the lift after the mouse moved while held. A field the guard brings back into view after putting a scroll back is one focused since the reader last scrolled that view, not one they scrolled away from (`scrolledFrom`): the middle press focuses the button under it. See `view-middle-autoscroll.test.cjs`.+- A scroll not the reader's is put back, so every way the reader scrolls has to count as theirs: the wheel and a trackpad's coast after the lift (WebKit on the Mac plays the coast itself and the page hears its scrolls with no wheel for each, so the wheel starts the same chain a touch fling does, `flings`/`flingUntil`: each scroll keeps the next one the reader's till it rests, and a click ends it; issenn on Discord, `view-trackpad-coast.test.cjs`), a touch and its fling, the keys, a drag, the scrollbar's own drag (`barDrag`, #1089) and the middle button's autoscroll (`panning`, 多喝热水 on Discord). Chromium and WebView2 give the autoscroll a press of button 1 and then no event of the reader's while it scrolls; from that press the view follows it till Chromium ends it, on the next press (which reaches the page only as a pointerup), a key (a keyup), or the lift after the mouse moved while held. A field the guard brings back into view after putting a scroll back is one focused since the reader last scrolled that view, not one they scrolled away from (`scrolledFrom`): the middle press focuses the button under it. See `view-middle-autoscroll.test.cjs`.- Typing never moves the page either. A textarea that grows with its text (the Library's `autosize` in plugins/library/client.js: a set's text, an agent's own text, a skill's description, a subagent's fields) is measured at height auto with what holds it kept at its height, so the page never goes short for a moment: a page gone short has its view's scroll clamped by the browser at every input, an input method's every composing step included, and the guard's putting it back pulled a textarea taller than the view to one of its edges (#2636, `library-ime-scroll.test.cjs`).- There are no native `<select>` elements and no colored left-border stripes. State is shown with a dot or a swatch.- What the window shows can be selected and copied, its controls can't, as in a Mac app (Outvi V on Discord: nothing could be copied into a bug report). The page is `user-select: none`, and two `:where()` rules after `body` in `app.css` make text content selectable (paragraphs, `pre` and `code`, a detail's values, hints and notes, every error class, a conversation, a request's story on Routing) and keep every control unselectable with what is in it (buttons, labels, tabs, menus, the navigation, grips). Both have no specificity, so a view's own rule still decides, as a list being sorted does; a field stays selectable. See `user-select.test.cjs`.diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.jsindex c2ca2b045..0a89a896d 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -23249,7 +23249,7 @@ function givesBack(e, dir) {for (const p of back) p.v.scrollTop += p.by;}let touchY = null;-addEventListener("wheel", (e) => { readerScrolls(250); givesBack(e, Math.sign(e.deltaY)); }, { capture: true, passive: true });+addEventListener("wheel", (e) => { flings(); givesBack(e, Math.sign(e.deltaY)); }, { capture: true, passive: true });addEventListener("touchstart", (e) => { touchY = e.touches[0]?.clientY ?? null; }, { capture: true, passive: true });addEventListener("touchmove", (e) => {readerScrolls(250);@@ -23259,10 +23259,10 @@ addEventListener("touchmove", (e) => {if (touchY != null) givesBack(e, Math.sign(touchY - y));touchY = y;}, { capture: true, passive: true });-// A flick goes on scrolling after the finger is lifted, with no touch event-// to say so: each of its scrolls keeps the next one the reader's, till it-// comes to rest. Put back, a phone's page jerked to and fro under the-// finger's flick (jiakun_zhao on X: 滚动会抽搐).+// A flick goes on after the finger lifts, and a trackpad's coast after the+// fingers do (WebKit on the Mac plays it with no wheel), with no event to say+// so: each of their scrolls keeps the next one the reader's till it rests.+// Put back, the page shook (jiakun_zhao on X: 滚动会抽搐; issenn: 高频振动并复位).let flingUntil = 0;const flings = () => { flingUntil = performance.now() + 250; readerScrolls(250); };addEventListener("touchend", flings, { capture: true, passive: true });diff --git a/internal/gui/tests/view-trackpad-coast.test.cjs b/internal/gui/tests/view-trackpad-coast.test.cjsnew file mode 100644index 000000000..77fb085c6--- /dev/null+++ b/internal/gui/tests/view-trackpad-coast.test.cjs@@ -0,0 +1,138 @@+// Run with Node's test runner and Playwright on the module path; see README.md.+// A trackpad's scroll goes on after the fingers lift (issenn on Discord,+// macOS app: 含滚动条的页面无法上下滚动……强行通过触摸板滚动页面会高频振动并复位).+// WebKit on the Mac carries that coast itself, frame by frame, and the page is+// told of the scrolls, not of a wheel for each: a wheel made the reader's+// moment only 250ms long, so the rest of the coast was put back as no one's,+// every frame, the page shaking where the wheel had left it and then back.+// Here the browser's coast is played by the page itself (a scroll each frame+// after the last trusted wheel, as a scroll by code is, since the page can't+// tell them apart either). It must stand to its end; a scroll by code once the+// page is at rest is still put back; and a click in the coast ends it, so what+// was clicked stays where it was (a click never scrolls the page).+// English and Chinese, Chromium and WebKit.+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_COAST_ASSETS || path.resolve(__dirname, "../assets");+const AGENTS = Array.from({ length: 14 }, (_, i) => ({+ id: "a" + i, name: "Agent " + i, path: "/t/a" + i + ".json", icon: "generic", wired: true,+ fields: [{ key: "model", label: "model", value: "m", options: [{ value: "m", label: "M", ref: "a/m" }] }],+}));++function server(lang) {+ return async (route) => {+ const url = new URL(route.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:true};` });+ if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });+ if (url.pathname === "/api/state") return json({ agents: AGENTS, profiles: [], settings: { lang, theme: "light" } });+ if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });+ 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 });+ };+}++// the page at rest: its scrollTop the same across a few frames' looks+async function rested(p, view, ms = 3000) {+ let last = NaN, same = 0;+ const until = Date.now() + ms;+ while (Date.now() < until) {+ const t = await view.evaluate((v) => v.scrollTop);+ same = t === last ? same + 1 : 0;+ if (same >= 3) return t;+ last = t;+ await p.waitForTimeout(50);+ }+ return last;+}++// the browser's coast after the lift: a scroll each frame, 6px slowing to 1px,+// for `ms` after the last wheel, with no wheel of its own. It counts what it+// asked for, and stops at the page's foot or when told to.+const coast = (v, ms) => new Promise((done) => {+ const end = performance.now() + ms;+ let d = 6, asked = 0;+ window.__coastStop = false;+ const step = () => {+ if (window.__coastStop || performance.now() > end || v.scrollTop + v.clientHeight >= v.scrollHeight - 1) return done(asked);+ v.scrollTop += Math.max(1, Math.round(d));+ asked += Math.max(1, Math.round(d));+ d *= 0.97;+ requestAnimationFrame(step);+ };+ requestAnimationFrame(step);+});++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ test(engine + ": a trackpad's coast after the lift is the reader's scroll", { timeout: 120000 }, async (t) => {+ assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");+ const browser = await (engine === "webkit" ? webkit : chromium).launch();+ t.after(() => browser.close());+ for (const lang of ["en", "zh"]) {+ await t.test(lang, async () => {+ const ctx = await browser.newContext({ viewport: { width: 440, height: 620 }, reducedMotion: "reduce" });+ const p = await ctx.newPage();+ p.setDefaultTimeout(8000);+ const errors = [];+ p.on("pageerror", (e) => { if (!/^ResizeObserver loop/.test(e.message)) errors.push(e.message); });+ await p.route("**/*", server(lang));+ const view = p.locator("#view-agents");+ await p.goto("http://magpie.test/?view=agents");+ await p.locator("#view-agents .ag-lead").first().waitFor();+ await rested(p, view);+ const over = await view.evaluate((v) => v.scrollHeight - v.clientHeight);+ assert(over > 600, `the page must be tall enough to coast: ${over}`);+ const r = await view.boundingBox();+ await p.mouse.move(r.x + r.width / 2, r.y + r.height / 2);++ // fingers on the pad: a few small wheels, then the coast, a second long+ const fingers = async () => { for (let i = 0; i < 5; i++) { await p.mouse.wheel(0, 8); await p.waitForTimeout(16); } };+ await fingers();+ const lifted = await view.evaluate((v) => v.scrollTop);+ const asked = await view.evaluate(coast, 1000);+ const end = await rested(p, view);+ assert(asked > 150, `the coast must ask for more than the 250ms after a wheel covers: ${asked}`);+ assert(end >= lifted + asked - 2, `the coast stands to its end: lifted at ${lifted}, coast asked ${asked}, left at ${end}`);++ // at rest, a scroll by code is put back as before+ await p.waitForTimeout(400);+ await view.evaluate((v) => { v.scrollTop -= 120; });+ await p.waitForTimeout(300);+ assert.equal(await rested(p, view), end, "a scroll by code at rest is put back");++ // a click in the coast ends it: what follows the click is put back,+ // and the row clicked stays where it was clicked+ await view.evaluate((v) => { v.scrollTop = 0; });+ await p.mouse.wheel(0, -2000);+ await rested(p, view);+ await p.waitForTimeout(400);+ await fingers();+ const going = view.evaluate(coast, 1500);+ await p.waitForTimeout(200);+ // pressed by coordinate, on the edge of the agent's row in the middle+ // of the window, as the reader's pointer is+ const [x, y] = await p.evaluate(([x, y]) => {+ const row = window.__clicked = document.elementFromPoint(x, y)?.closest(".row.agent");+ const b = row?.getBoundingClientRect();+ return b ? [b.left + 3, b.top + b.height / 2] : [0, 0];+ }, [r.x + r.width / 2, r.y + r.height / 2]);+ assert(x > 0, "an agent's row is in the middle of the window");+ const rowTop = () => p.evaluate(() => window.__clicked.getBoundingClientRect().top);+ await p.mouse.click(x, y);+ const at = await rowTop();+ await going;+ await rested(p, view);+ const after = await rowTop();+ assert(Math.abs(after - at) <= 12, `the click ends the coast: the row was at ${at} after the click, ${after} once at rest`);+ assert.deepEqual(errors, []);+ await ctx.close();+ });+ }+ });+}