gui: the scroll capsule sits above Plugins' install box and the Library's save and pick bars, not over Install (WaiooT on X)

scrollends.js lifted the capsule above only .after-list and .view-foot. Plugins > Discover's .pm-manual (and the Library's .lib-savebar, .lib-pickbar) are held at the window's foot too, so the capsule covered the Install button's right end. They are now in the list it steps over. No layout change.

Run (mica, copy of this tree): new view-ends-install-bar.test.cjs red on the old scrollends.js (390px: capsule over pm-browse, pm-minput and Install, all 12 subtests) and green on the new one (12 of 12: chromium and webkit, en/zh/zh-TW/ja/de, 390/560/980/1280 wide); with only the Library classes removed it is red at lib-savebar. go vet ./internal/gui/... and GOOS=windows go vet, gofmt -l clean. view-ends, view-ends-relayout, routing-editor-foot, plugin-manual-float and i18n-keys: 78 of 80 together; the 2 are webkit view-ends' first subtest (en 440 light) timing out at 8s in that batch, twice, while view-ends.test.cjs alone under BROWSER=webkit is 16 of 16 on this tree and on origin/main.

Not run: the whole GUI suite and go test ./... (mica held by another session's full GUI suite, mote at load 46; to be run at the pushed head), the Library's own bars with real fixtures (stand-in sticky bars of each class are used), the real Linux app.
This commit is contained in:
yetone
2026-11-20 00:08:39 +08:00
parent f288cc61af
commit 83bb079dee
3 changed files with 137 additions and 3 deletions
+1 -1
View File
@@ -767,7 +767,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/plugins/search/settings.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. When what the click does leaves the page shorter under it (a list emptied), the view keeps room at its foot for it to stay (`.view-room`), room that goes as the reader scrolls back. A control under what it unrolls (`data-unrolls`, "Show 7 more") goes down with what it opens: what's held is the part it is in, so the rows open downwards. A heading drawn anew whose only neighbour above is a zero-height pad (the first part of a skill group's windowed list) is marked so too: the hold passes over a neighbour with no height, so it held the next part's heading, which the rows opened pushed down, and the clicked one went off the top (jinpwng on X, `partHead` in plugins/library/client.js, `library-group-steady.test.cjs`). 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 page scrolled a screen down shows Scroll to top and Scroll to bottom (emo172, #1090): a small capsule of two chevron buttons at the open page's lower right, in its right margin when a wide window leaves one, else over its corner; above Providers' sticky Add buttons. It goes again near the page's top and over a dialog, and, over the corner, at the page's foot, where the last row can't scroll out from under it, unless it has the pointer or focus. It is placed again on a scroll, a resize, a page shown or hidden, and whenever the open page or one of its own children changes size (a `ResizeObserver`, so a Routing group opened or closed moves it off the editor with no scroll, Jiabubu; see `view-ends-relayout.test.cjs`). It never changes the page's height, which the guard below measures. A press is the reader's scroll (`scrollOnPurpose`, then `arrived` once the page stands still), smooth unless motion is reduced; Scroll to bottom is `aria-disabled` at the foot. Each button's name and tooltip are in every language. The code is [`scrollends.js`](../../internal/gui/assets/scrollends.js), imported on the window's first scroll so the core doesn't carry it; the tray panel has none. Home and End scroll a page as before. See `view-ends.test.cjs`.
- A page scrolled a screen down shows Scroll to top and Scroll to bottom (emo172, #1090): a small capsule of two chevron buttons at the open page's lower right, in its right margin when a wide window leaves one, else over its corner; above Providers' sticky Add buttons and any other sticky foot the page holds at its bottom (a Routing group editor's bar, Plugins' install box `.pm-manual`, the Library's `.lib-savebar` and `.lib-pickbar`: the capsule covered Install, WaiooT on X; `view-ends-install-bar.test.cjs`). It goes again near the page's top and over a dialog, and, over the corner, at the page's foot, where the last row can't scroll out from under it, unless it has the pointer or focus. It is placed again on a scroll, a resize, a page shown or hidden, and whenever the open page or one of its own children changes size (a `ResizeObserver`, so a Routing group opened or closed moves it off the editor with no scroll, Jiabubu; see `view-ends-relayout.test.cjs`). It never changes the page's height, which the guard below measures. A press is the reader's scroll (`scrollOnPurpose`, then `arrived` once the page stands still), smooth unless motion is reduced; Scroll to bottom is `aria-disabled` at the foot. Each button's name and tooltip are in every language. The code is [`scrollends.js`](../../internal/gui/assets/scrollends.js), imported on the window's first scroll so the core doesn't carry it; the tray panel has none. Home and End scroll a page as before. See `view-ends.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 wheel or coast the page is never told of (macOS 13's WebKit, Safari 16.6's, scrolled a view under wheels it never dispatched, so every scroll was put back and only the bar's drag moved the page: three scrolls put back the same way within a second are taken as the reader's run and given back, and so is each one after it that goes on the same way within a second of the last, so a wheel turned slowly or on a loaded Mac loses no step; a scroll by code is one, not a run, and two at rest are still put back; issenn on Discord, `view-wheel-unheard.test.cjs`. Under a click's 4s hold the same holds: only a put-back that comes with the page redrawn since the hold last held (`redrawn`: the view's height or where the first held parts sit moved from `h.lay`) is the hold's and never counts toward a run, so a profile opened on the Agents page and wheeled through at once scrolls, issennknight on Discord, `view-wheel-after-click.test.cjs`. The parts `h.lay` measures are those still in the page that scroll with it: a part drawn again since (the Usage page's tabs, the agents' list under an agent opened or closed) is a redraw once, not at every scroll, and a sticky one (Settings' tabs at a narrow width) is left out, as it sits still while the page scrolls; `view-wheel-after-redraw.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`.
- A load that lands puts the view back where the reader left it (`show`'s `back` on the page's first reads, the Providers pages' reload after `render`): what it drew may have pulled the view up, the browser clamping it to a page shorter for a moment. While the reader scrolls, the place last heard is late (the page hears of a scroll a frame or more after it, WebKit scrolling on its own thread), and putting it back took their last steps and stopped their coast each time a load landed under the wheel, so Routing and Usage, scrolled as they opened, shook and snapped back (issennknight on Discord, macOS 13). `backAfterLoad` keeps a view that has gone on the way the reader's own scrolls go (`readerWay`, set from each scroll of theirs) as theirs, and puts back only a move against it, which is a redraw's clamp. The browser's scroll anchoring stays on: as data comes in above, it lowers `scrollTop` with what's on the screen still, which the reader never sees, so the test tells a put-back (the view up, what was under the pointer going down with it) from that.
- The Usage page's allowance cards come in at different times (each vendor's read while `X-Magpie-Reading` asks again, then the curves' history), and a card drawn above the one being read used to push it down the screen (liuzhengdong99 on X). Overview keeps the card being read in place (`keepInView(..., true)` in `plugins/usage/page.js`: the highest card, or part of the page under them, starting in sight; found again by its `data-key` once `renderQuotas` draws the cards anew, and followed after every `packUsage`). Such a view leaves the browser's own anchoring on while it keeps nothing (at its top, on another tab, and while the cards are dragged or moved by keys: `unpin`, so a card lands where its slot showed). Each card's height drawn in full is kept by its key (`usageTall`, localStorage `magpie.usageCardTall`), and a card still waiting on its read or its curve (`usageWaiting`; the history's first answer ends the wait, an empty one too, `loadQuotaHist`) is packed at least that tall, and packed in the number of columns they were last drawn whole in at that width (`usageTall["#" + most]`), since the heights kept are that layout's; so on the next start the cards fill in without the page moving. See `usage-cards-steady.test.cjs`.
+3 -2
View File
@@ -38,8 +38,9 @@
box.classList.toggle("on", on || held);
let bottom = innerHeight - r.bottom + 16;
// above a page's own sticky foot under it (Providers' Add buttons, a
// Routing group editor's Cancel and Add: Jiabubu on Discord)
for (const foot of v.querySelectorAll(":scope > .after-list:not(.away), .view-foot")) {
// Routing group editor's Cancel and Add: Jiabubu on Discord; Plugins'
// install box, the Library's save and pick bars: WaiooT on X)
for (const foot of v.querySelectorAll(":scope > .after-list:not(.away), .view-foot, .pm-manual, .lib-savebar, .lib-pickbar")) {
const f = foot.getBoundingClientRect();
if (getComputedStyle(foot).position === "sticky" && f.bottom > innerHeight - bottom - box.offsetHeight && f.top < innerHeight - bottom) bottom = Math.max(bottom, innerHeight - f.top + 8);
}
@@ -0,0 +1,133 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Plugins > Discover's install box ("Have one in mind?") is held at the
// window's foot, and the Scroll to top / Scroll to bottom capsule
// (scrollends.js) sat over its right end, covering the Install button
// (WaiooT on X, zh, a ~1000px window). With the page a screen down the
// capsule is above the box and over none of its parts, and Install takes a
// click at its right end. The Library's save and pick bars are held at the
// foot the same way (a stand-in sticky bar of each class is put at the end of
// the view here, as the Library's own fixtures are heavy); the capsule steps
// over them too. Both engines, every language, at 390, 560, 980 and 1280.
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 listings = Array.from({ length: 40 }, (_, i) => ({
package: "@magpie-community/opencode-p" + i + "-auth", name: "Plan " + i, community: true, providers: ["p" + i],
summary: { en: "Signs in to plan " + i + " and serves its models" }, npm: { version: "0.1." + i },
}));
const state = { bun: true, bunVersion: "1.3.0", plugins: [], picker: true, registry: { url: "https://registry.npmjs.org", from: "npmrc", path: "~/.npmrc" } };
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:false};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
if (url.pathname === "/api/plugins") return json(state);
if (url.pathname === "/api/plugins/listings") return json({ listings });
if (url.pathname === "/api/plugins/market") return json({ listings, state });
if (url.pathname === "/api/plugins/github") return json({ repos: [], topic: "magpie-plugin" });
if (url.pathname === "/api/plugins/search") return json({ hits: [] });
if (url.pathname.startsWith("/api/")) return json({});
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
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)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const SIZES = [[390, 700], [560, 640], [980, 620], [1280, 600]];
// the reader's wheel takes the view to a share of its scroll (magpie puts
// back a scroll no reader asked for), and waits for it to stop there
async function scrollTo(page, f) {
const v = page.locator("#view-plugins");
const b = await v.boundingBox();
await page.mouse.move(b.x + b.width / 2, b.y + Math.min(b.height / 2, 200));
const near = ([top, max]) => f >= 1 ? top >= max - 1 : Math.abs(top - max * f) <= 40;
const read = () => v.evaluate((e) => [e.scrollTop, e.scrollHeight - e.clientHeight]);
for (let i = 0; i < 100; i++) {
let at = await read();
if (near(at)) {
await page.waitForTimeout(250);
at = await read();
if (near(at)) return at;
}
await page.mouse.wheel(0, Math.max(-600, Math.min(600, Math.round(at[1] * f) - at[0] + (f >= 1 ? 50 : 0))));
await page.waitForTimeout(60);
}
return read();
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": the scroll capsule is above Discover's install box, not over Install", async (t) => {
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"]) {
await t.test(lang, async () => {
const ctx = await browser.newContext({ viewport: { width: SIZES[0][0], height: SIZES[0][1] } });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang));
await page.goto("http://magpie.test/?view=plugins");
const view = page.locator("#view-plugins");
await view.locator(".pm-manual").waitFor();
await view.locator(".pm-bar .pm-kinds .opt").nth(1).click();
await page.waitForFunction((n) => document.querySelectorAll("#view-plugins .pm-card").length >= n, listings.length);
for (const [w, h] of SIZES) {
const size = `${w}x${h}`;
await page.setViewportSize({ width: w, height: h });
await scrollTo(page, 0.6);
await page.waitForFunction(() => document.querySelector(".view-ends.on"));
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(r, 250)))));
const m = await page.evaluate(() => {
const box = (e) => { const b = e.getBoundingClientRect(); return { top: b.top, bottom: b.bottom, left: b.left, right: b.right }; };
const man = document.querySelector("#view-plugins .pm-manual");
return { ends: box(document.querySelector(".view-ends")), man: box(man), parts: [...man.querySelectorAll("button, input, a")].map((e) => ({ what: e.className || e.tagName, ...box(e) })), install: box(man.querySelector("button[type=submit]")) };
});
const hit = (a, b) => a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
for (const p of m.parts) assert(!hit(p, m.ends), `${size}: the capsule over ${p.what}: ${JSON.stringify([p, m.ends])}`);
assert(m.ends.bottom <= m.man.top + 1, `${size}: the capsule above the box: ${JSON.stringify([m.ends, m.man])}`);
// Install's right end is Install's
const at = await page.evaluate((r) => document.elementFromPoint(r.right - 3, (r.top + r.bottom) / 2)?.closest("button")?.type, m.install);
assert.equal(at, "submit", `${size}: Install's right end is Install's`);
// the Library's bars, held the same way: stand-ins at the view's end
for (const cls of ["lib-savebar", "lib-pickbar"]) {
const r = await page.evaluate((cls) => {
const v = document.querySelector("#view-plugins");
const man = v.querySelector(".pm-manual");
man.hidden = true;
const bar = document.createElement("div");
bar.className = cls;
bar.style.cssText = "position:sticky;bottom:8px;height:44px;margin-top:8px;display:block";
v.append(bar);
return new Promise((res) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(() => {
const e = document.querySelector(".view-ends").getBoundingClientRect(), b = bar.getBoundingClientRect();
bar.remove();
man.hidden = false;
res({ ends: e, bar: b, on: document.querySelector(".view-ends").classList.contains("on") });
}, 250))));
}, cls);
assert(r.on, `${size} ${cls}: the capsule is in`);
assert(r.ends.bottom <= r.bar.top + 1, `${size} ${cls}: the capsule above the bar: ${JSON.stringify(r)}`);
}
}
assert.deepEqual(errors, []);
});
}
});
}