settings: with the tabs across the top, Settings' tabs and search stay at the top of a long part (#2396, gif156359098)

In the top-menu layout the Settings head (#setTabs and the find-a-setting
box) sat in the .view scroller and scrolled away with a long part such as
About, so another part was a scroll back up away. It is position: sticky
now, in that layout only (body:not(.side-nav)), on the same frosted strip
the Library's and the Plugins' heads have (.lib-head): the strip is the
head's ::before, reaching over the view's side padding and the head's 4px
and 6px margins so no row shows through above or below it, and a hairline
shows once the page has scrolled (a scroll listener sets .stuck, as the
Library's does). The window's view is padded 2px at the top, so the head
stops at -2px there, as .lib-head does. At scrollTop 0 nothing moves: the
strip is the page's colour and sticky changes no layout. With the sidebar
the head stays position: fixed in the title bar, with no strip.

Siblings: the Library's .lib-head and the Plugins' head (class
"lib-head pm-head") were already sticky in the top layout (library.css),
so they are only checked, not changed.

Run (worktree off origin/main 37fec1240):
- new internal/gui/tests/settings-tabs-stick.test.cjs, BROWSER=chromium
  and webkit, 16/16 each: top layout at 1100 and 420px in en, zh, zh-TW,
  ja, de: at scrollTop 0 the head and the part under it are in their own
  places; wheeled to About's foot the head is at the view's top, every tab
  and the search box is the element under its own middle, the strip is
  there, opaque and covers view top to past the head's margin, .stuck set;
  clicking General opens it with the head still at the top; the Library's
  head at the top at its foot; the Plugins' head is sticky. Sidebar layout
  in every language: head fixed at y=0 before and after scrolling, no
  ::before strip.
- broken by hand, each went red: position: sticky removed (11 fail in
  both engines, "the tabs at the top of the view: -306"); the strip's
  content: none (11 fail, "a strip under the tabs"); the strip at
  top/bottom 0 instead of -6px (webkit 11 fail, "the strip covers...");
  the ::before rule unscoped from :not(.side-nav) (6 fail, sidebar "no
  strip of its own in the title bar"). Top: 0 for the window first failed
  the test at gap 2px, hence top: -2px there.
- existing GUI tests, chromium and webkit, all green: settings-general,
  settings-groups, settings-proxy-auth, settings-search,
  settings-sections, settings-shortcut, sidebar-tab-top, sidebar,
  side-toggle, side-width, library-backups-top, library-discover-jump,
  plugin-market, click-scroll, view-scrollbar.
- go test -tags nogui ./internal/gui/ ok (no Go files changed; gofmt/vet
  have nothing to check).
- screenshots of About scrolled half-way, light and dark, zh, 1100px,
  looked at: tabs and search on the strip, rows passing under it.
Not tried: the real Windows app (the reporter's), WebKitGTK.

Full suite: SUITE_LINE
This commit is contained in:
yetone
2026-10-15 23:08:05 +08:00
parent d98e17808b
commit 8f55c27ad0
3 changed files with 229 additions and 0 deletions
+19
View File
@@ -3091,6 +3091,25 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
when they fill it; while it holds words, each part's rows that say them
under the part's name, and the tabs set aside */
#view-settings .set-head { flex-wrap: wrap; gap: 6px; }
/* with the tabs across the top (the sidebar has them in the title bar) the
parts' tabs and the search stay at the top of the page while a long part
(About) scrolls under them, on the frosted strip the Library's and the
Plugins' tabs have (.lib-head), a hairline once something is beneath
(#2396). The strip is the head's ::before, reaching over the view's
padding and the head's margins so no row shows through above or below
it; at the page's top it is the page's own colour, nothing moved. The
window's view is padded 2px at the top: the head stops over it */
body:not(.side-nav) #view-settings .set-head { position: sticky; top: 0; z-index: 5; --bleed-l: 12px; --bleed-r: 12px; }
body.window:not(.side-nav) #view-settings .set-head { top: -2px; --bleed-l: 16px; --bleed-r: 16px; }
body:not(.side-nav) #view-settings .set-head::before {
content: ""; position: absolute; z-index: -1; pointer-events: none;
top: -6px; bottom: -6px; left: calc(-1 * var(--bleed-l)); right: calc(-1 * var(--bleed-r));
background: color-mix(in srgb, var(--bg) 92%, transparent);
-webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
box-shadow: 0 1px 0 transparent; transition: box-shadow .18s var(--ease);
}
body:not(.side-nav) #view-settings .set-head.stuck::before { box-shadow: 0 1px 0 var(--line-2); }
@supports not (color: color-mix(in srgb, red 50%, blue)) { body:not(.side-nav) #view-settings .set-head::before { background: var(--bg); } }
.set-q { flex: 0 1 180px; margin-left: auto; min-width: 120px; }
.set-searching .set-tabs { display: none; }
.set-searching .set-q { flex: 1 1 100%; width: 100%; margin-left: 0; }
+4
View File
@@ -18277,6 +18277,10 @@ function setSetTab(tab, remember) {
if (b) setSetTab(b.dataset.set, true);
};
tabKeys(tabs, "button[data-set]");
// the tabs held at the top (app.css, #2396): a hairline under them once
// the page has scrolled beneath, as the Library's
const sv = $("#view-settings");
sv.addEventListener("scroll", () => sv.querySelector(":scope > .set-head").classList.toggle("stuck", sv.scrollTop > 0), { passive: true });
// opened on a part (a reload, a link): that part, and remembered
if (mode === "window" && params.get("view") === "settings" && SET_TABS.includes(params.get("tab"))) {
setTab = params.get("tab");
@@ -0,0 +1,206 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// #2396 (gif156359098): with the tabs across the top (the sidebar off), the
// Settings tabs and the find-a-setting box scrolled away with a long part
// (About), so another part was a scroll back up away. They stay at the top
// of the page now while the part scrolls under them, on a strip the rows
// don't show through, and a tab there still opens its part. At the page's
// top nothing moved. The Library's and the Plugins' tabs already stayed
// (.lib-head); the Library's is checked the same way. With the sidebar the
// tabs are in the title bar as before. Chromium and WebKit, a wide and a
// narrow window, every language; no backend, the API is faked here.
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 HOME = "/Users/aimer";
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
const lib = {
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
agents: [agent("codex", "Codex"), agent("pi", "Pi")],
instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [],
servers: Array.from({ length: 30 }, (_, i) => ({ name: `server-${i + 1}`, transport: "stdio", command: "npx", args: ["fs-mcp"], agents: ["codex"] })),
};
const settings = (lang) => ({
theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", textSize: 100,
dock: false, dockWindow: false, proxy: "", redact: false, redactPersonal: false, redactWords: [],
codexWarmup: "", claudeWarmup: "", codexWarmAt: "", claudeWarmAt: "", workbuddyCheckin: false, noStats: false,
trayUsage: "", trayUsageEvery: 3, vision: "", imageGen: "",
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425",
proxyNow: "none", proxySource: "none", login: false,
visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [],
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
});
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:${JSON.stringify(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/settings") return json(settings(lang));
if (url.pathname === "/api/library") return json(lib);
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
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 });
};
}
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
const scrollTop = (page, v) => page.locator(v).evaluate((e) => e.scrollTop);
// down to the view's foot by the wheel, as the reader goes there
async function toFoot(page, v) {
const box = await page.locator(v).boundingBox();
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
for (let i = 0; i < 60; i++) {
await page.mouse.wheel(0, 300);
await page.waitForTimeout(20);
if (await page.locator(v).evaluate((e) => e.scrollTop + e.clientHeight >= e.scrollHeight - 1)) break;
}
await page.waitForTimeout(300);
const at = await scrollTop(page, v);
assert.ok(at > 100, `${v} scrolled down: ${at}`);
return at;
}
// where the head is against its view's visible top, and whether each of its
// controls is the thing under its own middle (nothing drawn over it, not
// scrolled off)
const headAt = (page, v, head) => page.evaluate(([v, head]) => {
const view = document.querySelector(v), h = view.querySelector(head);
const vr = view.getBoundingClientRect(), hr = h.getBoundingClientRect();
const hit = [...h.querySelectorAll("button:not([hidden]), input")].filter((c) => c.getClientRects().length).map((c) => {
const r = c.getBoundingClientRect(), e = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2);
return !!e && (e === c || c.contains(e));
});
return { gap: hr.top - (vr.top + view.clientTop), top: hr.top, controls: hit.length, under: hit.every(Boolean) };
}, [v, head]);
// the strip's paint: a row scrolled beneath must not show through it
// and where it reaches: from the view's visible top to past the head's margin
const strip = (page, sel) => page.locator(sel).evaluate((h) => {
const b = getComputedStyle(h, "::before"), hs = getComputedStyle(h), v = h.closest(".view");
const hr = h.getBoundingClientRect(), vtop = v.getBoundingClientRect().top + v.clientTop;
return {
content: b.content, bg: b.backgroundColor, position: hs.position,
over: b.content !== "none" && hr.top + parseFloat(b.top) <= vtop + 0.5 && hr.bottom - parseFloat(b.bottom) >= hr.bottom + parseFloat(hs.marginBottom) - 0.5,
};
});
const opaque = (bg) => {
const m = bg.match(/[\d.]+/g)?.map(Number) || [];
if (bg.startsWith("color(")) return (m.length > 4 ? m[m.length - 1] : 1) >= 0.9;
return m.length === 3 || (m.length === 4 && m[3] >= 0.9);
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: Settings' tabs stay at the top of a long part (#2396)`, async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const open = async (lang, width, layout) => {
const context = await browser.newContext({ viewport: { width, height: 400 }, reducedMotion: "reduce" });
await context.addInitScript((layout) => {
try { localStorage.setItem("magpie.settingsTab", "about"); localStorage.setItem("magpie.libTab", "mcp"); localStorage.setItem("magpie.navLayout", layout); } catch {}
}, layout);
const page = await context.newPage();
page.setDefaultTimeout(5000);
page.errors = [];
page.on("pageerror", (e) => page.errors.push(e.message));
await page.route("**/*", server(lang));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
return page;
};
for (const width of [1100, 420]) for (const lang of LANGS) await t.test(`tabs across the top, ${width}px, ${lang}`, async () => {
const page = await open(lang, width, "top");
assert.ok(!(await page.evaluate(() => document.body.classList.contains("side-nav"))), "no sidebar");
const set = "#view-settings";
await page.locator("#prefs").click();
await page.locator("#about .row").first().waitFor();
assert.equal(await page.locator("#setTab-about").getAttribute("aria-selected"), "true");
// at the page's top the head is where it always was: under the view's
// padding and its own margin, the part under it past its margin
const rest = await page.evaluate(() => {
const v = document.querySelector("#view-settings"), h = v.querySelector(".set-head"), p = document.querySelector("#setPage-about");
const cs = getComputedStyle(v), hs = getComputedStyle(h);
return {
gap: h.getBoundingClientRect().top - v.getBoundingClientRect().top - v.clientTop - parseFloat(cs.paddingTop) - parseFloat(hs.marginTop),
below: p.getBoundingClientRect().top - h.getBoundingClientRect().bottom - parseFloat(hs.marginBottom),
stuck: h.classList.contains("stuck"),
};
});
assert.ok(Math.abs(rest.gap) <= 0.5, `at the top the head is in its own place: ${rest.gap}`);
assert.ok(Math.abs(rest.below) <= 0.5, `and the part right under it: ${rest.below}`);
assert.equal(rest.stuck, false, "no hairline at the top");
// About at its foot: the tabs and the search are at the view's top,
// each one under nothing, on a strip the rows don't show through
await toFoot(page, set);
const at = await headAt(page, set, ".set-head");
assert.ok(at.gap >= -0.5 && at.gap <= 1, `the tabs at the top of the view: ${at.gap}`);
assert.ok(at.controls >= 9, `every tab and the search box seen: ${at.controls}`);
assert.ok(at.under, "nothing over the tabs or the search box");
const s = await strip(page, `${set} .set-head`);
assert.equal(s.position, "sticky");
assert.notEqual(s.content, "none", "a strip under the tabs");
assert.ok(opaque(s.bg), `the strip hides what scrolls under it: ${s.bg}`);
assert.ok(s.over, "the strip covers from the view's top to the part under the head");
assert.ok(await page.locator(`${set} .set-head`).evaluate((h) => h.classList.contains("stuck")), "a hairline once something is beneath");
assert.ok(await page.locator("#setQ").isVisible(), "the search box is there");
// a tab there opens its part
await page.locator("#setTab-general").click();
await page.waitForFunction(() => document.querySelector("#setTab-general").getAttribute("aria-selected") === "true");
assert.ok(await page.locator("#setPage-general").isVisible(), "General shown");
assert.equal(await page.locator("#setPage-about").isVisible(), false, "About hidden");
const after = await headAt(page, set, ".set-head");
assert.ok(after.gap >= -0.5 && after.gap <= 1, `the tabs still at the top: ${after.gap}`);
// the Library's tabs, the same way (they stayed already: .lib-head)
const libv = "#view-library";
await page.locator('#nav button[data-view="library"]').click();
await page.locator(`${libv} .lib-row, ${libv} .row`).first().waitFor();
await toFoot(page, libv);
const la = await headAt(page, libv, ".lib-head");
assert.ok(la.gap >= -2.5 && la.gap <= 1, `the Library's tabs at the top of the view: ${la.gap}`);
assert.ok(la.under, "nothing over the Library's tabs");
await page.locator(`${libv} .lib-tabs > button`).nth(0).click();
await page.waitForFunction(() => document.querySelectorAll("#view-library .lib-tabs > button")[0]?.classList.contains("on"));
// and the Plugins' head is the same strip
await page.locator('#nav button[data-view="plugins"]').click();
await page.locator("#view-plugins .pm-head").waitFor();
assert.equal((await strip(page, "#view-plugins .pm-head")).position, "sticky", "the Plugins' tabs stay too");
assert.deepEqual(page.errors, []);
await page.context().close();
});
// with the sidebar the head is in the title bar, as before: fixed there,
// no strip of its own, at the window's top at the foot of About too
for (const lang of LANGS) await t.test(`sidebar, ${lang}`, async () => {
const page = await open(lang, 1100, "side");
assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "the sidebar is shown");
await page.locator("#prefs").click();
await page.locator("#about .row").first().waitFor();
const s = await strip(page, "#view-settings .set-head");
assert.equal(s.position, "fixed");
assert.equal(s.content, "none", "no strip of its own in the title bar");
const y0 = await page.locator("#view-settings .set-head").evaluate((h) => h.getBoundingClientRect().top);
assert.equal(y0, 0, "in the title bar");
await toFoot(page, "#view-settings");
assert.equal(await page.locator("#view-settings .set-head").evaluate((h) => h.getBoundingClientRect().top), 0, "still in the title bar");
assert.ok(await page.locator("#setQ").isVisible(), "the search box in the title bar");
assert.deepEqual(page.errors, []);
await page.context().close();
});
});
}