routing: a group editor's Cancel and Add have the scroll capsule above them, their ground to the window's edge

jiabubu on Discord: in a Routing group editor, its bar of Cancel and Add,
held at the window's foot while the editor runs on below, had the Scroll
to top and Scroll to bottom capsule over Add, and under the bar's ground a
gap above the window's bottom edge.

- The capsule (scrollends.js) rose above Providers' sticky Add bar only.
  It now rises above any page foot marked .view-foot that is under it,
  and the editor's bar is one. A foot elsewhere on the page, not under
  the capsule, leaves it where it was.
- The bar was held at bottom: 0, which stops at the view's own foot
  padding (4px, 8px in the window, max(12px, the safe area) on the phone
  page, from app.css), so that much of the page showed under it. It is
  now held that far down, its ground to the window's edge; on a phone
  page its buttons keep the safe area under them.

routing-editor-foot.test.cjs: sixteen groups, then New group, scrolled so
the page is a screen down and the editor runs on below the window: the
bar's foot at the window's edge, the capsule above the bar and over none
of its buttons, and Add's right end taking a click as Add. Desktop 1100,
700, 560; browser page 1100, 700, 440, 360; Chromium and WebKit,
en/zh/zh-TW/ja/de.

Run on mote (mote-run):
- routing-editor-foot, Chromium and WebKit, en/zh/zh-TW/ja/de: 10 of 10
  ok.
- At b3cf5641a (this change on 96acc59c4): routing-editor-foot,
  view-ends, old-webkit, group-editor-selected, group-editor-fits,
  group-editor-align, group-first-token, group-patience, group-morph,
  group-new-head, group-member-drag, routing-rows-fit, drag-rows-shift,
  click-scroll, i18n-keys and routing-rule-drag, both engines, every
  language they run, at concurrency 3: 179 of 184 ok; go test -run Budget
  ./internal/gui ok. The reds:
  - routing-rule-drag in Chromium (4), at its hover check before any
    drag, the same alone at origin/main (#3789).
  - group-first-token WebKit en 420, the editor's bar over the option a
    click scrolled to. It went red the same way before this change, under
    a larger run (#5007); alone at this tree it is 30 of 30.

Broken by hand, each 10 of 10 red in the new test:
- all three files as at origin/main: "desktop 1100px: the bar's ground
  down to the window's edge, no gap: bar 552, window 560".
- scrollends.js only: "the capsule above the bar: 489-544, bar from 511".
- routing.css only: the gap again (552 vs 560).

Not tried: the Windows app (WebView2) itself, and a phone with a home
indicator (safe area) in a real browser.
This commit is contained in:
yetone
2026-11-03 12:14:06 +08:00
parent 8af751987c
commit 2cfeda3d3a
4 changed files with 116 additions and 5 deletions
@@ -7482,7 +7482,7 @@ function routingPage(part) {
drawLevels();
ed.append(el("label", "", t("Levels")), lw);
const bar = el("div", "bar");
const bar = el("div", "bar view-foot");
if (g) {
const del = el("button", "text danger", t("Remove"));
del.onclick = () => groupAction("delete", { id: g.id }, t("{name} removed", { name: g.name }));
@@ -586,7 +586,12 @@ button.rt-session { cursor: pointer; }
.rt-groups > .rt-gedit:last-child { border-radius: 0 0 11px 11px; }
.rt-groups > .rt-gedit:only-child { border-radius: 11px; }
.rt-groups > .rt-gedit + * { border-top-color: transparent; }
.rt-gedit > .bar { position: sticky; bottom: 0; z-index: 3; background: var(--ged-bg, var(--card)); padding-bottom: 10px; margin-bottom: -10px; }
/* the editor's Cancel and Add stay in sight, the bar's ground down to the
window's edge: the view's own foot padding (.view, body.window and the
phone page's in app.css) under it had shown as a gap (Jiabubu on Discord) */
.rt-gedit > .bar { position: sticky; bottom: calc(-1 * var(--vfoot, 4px)); z-index: 3; background: var(--ged-bg, var(--card)); padding-bottom: calc(10px + var(--safe, 0px)); margin-bottom: calc(-10px - var(--safe, 0px)); }
body.window .rt-gedit > .bar { --vfoot: 8px; }
@media (max-width: 760px), (pointer: coarse) and (max-width: 1024px) { body.web .rt-gedit > .bar { --vfoot: max(12px, env(safe-area-inset-bottom)); --safe: env(safe-area-inset-bottom, 0px); } }
.rt-gedit > .bar > button.text:not(.danger) { height: 28px; padding: 0 12px; border-radius: 7px; font-size: 13px; }
.rt-gedit .ehead.folds { cursor: pointer; }
.rt-gedit .ehead.folds:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
+6 -3
View File
@@ -36,9 +36,12 @@
if (!gutter && v.scrollHeight - v.clientHeight - v.scrollTop < box.offsetHeight + 24) on = false;
box.classList.toggle("on", on || held);
let bottom = innerHeight - r.bottom + 16;
// above a page's own sticky foot (Providers' Add buttons)
const foot = v.querySelector(":scope > .after-list:not(.away)");
if (foot && getComputedStyle(foot).position === "sticky") bottom = Math.max(bottom, innerHeight - foot.getBoundingClientRect().top + 8);
// 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")) {
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);
}
box.style.right = Math.max(8, innerWidth - r.right + bar + (gutter ? (pad - box.offsetWidth) / 2 : 10)) + "px";
box.style.bottom = bottom + "px";
up.setAttribute("aria-disabled", v.scrollTop < 1);
@@ -0,0 +1,103 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// A Routing group editor's Cancel and Add, held at the window's foot while
// the editor runs on below it (Jiabubu on Discord): the Scroll to top and
// Scroll to bottom capsule (scrollends.js) sat over Add, and under the bar's
// ground the view's own foot padding showed as a gap above the window's
// edge. Here a New group editor on a long Routing page is scrolled so its
// bar is held: the bar's ground reaches the window's edge, and the capsule,
// once in, is above the bar and over none of its buttons. Chromium and
// WebKit, the desktop window and the browser page, wide and narrow,
// en/zh/zh-TW/ja/de.
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 models = Array.from({ length: 4 }, (_, i) => ({ id: `p/m${i}`, name: `m${i}`, providerName: "P", icon: "generic" }));
const ids = models.map((m) => m.id);
// enough groups above for the page to be scrolled a screen down
const groups = {
models, pools: [],
groups: Array.from({ length: 16 }, (_, i) => ({ id: `g${i}`, name: `group ${i}`, routing: "order", members: ids, ready: true, memberInfo: ids.map((id) => ({ id, ready: true })), offers: [], shared: [] })),
};
function serve(lang, web) {
const state = { agents: [{ id: "codex", name: "Codex", path: "/t", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
return async (r) => {
const url = new URL(r.request().url());
const json = (data) => r.fulfill({ json: data });
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web}};` });
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json(state);
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/gateway/trace") {
if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes
return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
}
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
if (url.pathname === "/api/groups") return json(groups);
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], 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 r.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType });
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
test(`${engine} ${lang}: a group editor's Cancel and Add, held at the foot, have the capsule above them and no gap under`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const web of [false, true]) {
for (const width of web ? [1100, 700, 440, 360] : [1100, 700, 560]) {
const at = `${web ? "web" : "desktop"} ${width}px`;
const page = await browser.newPage({ viewport: { width, height: 560 }, reducedMotion: "reduce" });
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, web));
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-group").nth(15).waitFor();
await page.locator(".rt-newgroup:visible").first().click();
await page.locator(".rt-gedit").waitFor();
// the editor's top just under the window's: the page a screen
// down, the editor running on below, its bar held at the foot
await page.evaluate(() => {
const v = document.querySelector("#view-routing"), e = document.querySelector(".rt-gedit");
v.scrollTop += e.getBoundingClientRect().top - v.getBoundingClientRect().top - 20;
if (v.scrollTop <= v.clientHeight) { // the editor near the top: groups go above it
v.scrollTop = v.clientHeight + 40;
}
});
// the capsule comes on the window's scroll, a frame later
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 v = document.querySelector("#view-routing"), e = document.querySelector(".rt-gedit"), bar = e.querySelector(":scope > .bar");
return { view: box(v), ed: box(e), bar: box(bar), ends: box(document.querySelector(".view-ends")), buttons: [...bar.querySelectorAll("button")].map((b) => ({ text: b.textContent, ...box(b) })), scrolled: v.scrollTop > v.clientHeight };
});
assert(m.scrolled && m.ed.bottom > m.view.bottom + 40, `${at}: the page a screen down and the editor running on below the window: ${JSON.stringify([m.ed, m.view])}`);
assert(Math.abs(m.bar.bottom - m.view.bottom) <= 1, `${at}: the bar's ground down to the window's edge, no gap: bar ${m.bar.bottom}, window ${m.view.bottom}`);
assert(m.ends.bottom <= m.bar.top + 1, `${at}: the capsule above the bar: ${m.ends.top}-${m.ends.bottom}, bar from ${m.bar.top}`);
for (const b of m.buttons) {
const over = b.left < m.ends.right && b.right > m.ends.left && b.top < m.ends.bottom && b.bottom > m.ends.top;
assert(!over, `${at}: the capsule over ${b.text}: ${JSON.stringify([b, m.ends])}`);
}
// Add still takes a click where it is drawn
const add = page.locator(".rt-gedit > .bar button.primary");
const ab = await add.boundingBox();
const hit = await page.evaluate(([x, y]) => document.elementFromPoint(x, y)?.closest("button")?.classList.contains("primary"), [ab.x + ab.width - 4, ab.y + ab.height / 2]);
assert(hit, `${at}: Add's right end is Add's, nothing over it`);
assert.deepEqual(errors, [], `${at}: no page error`);
await page.close();
}
}
});
}
}