diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 94932d54f..cc83422bd 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -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; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 708f4d2c3..d064c52d8 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -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"); diff --git a/internal/gui/tests/settings-tabs-stick.test.cjs b/internal/gui/tests/settings-tabs-stick.test.cjs new file mode 100644 index 000000000..38e7e09ce --- /dev/null +++ b/internal/gui/tests/settings-tabs-stick.test.cjs @@ -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(); + }); + }); +}