gui: the sidebar's button stays in one place whether the sidebar shows or not (ztf4080 on X)

ztf4080: "左侧栏收起按钮在左上角,但是收起后展开按钮变了右下角". The button
to hide the sidebar sat in the page header to the right of the sidebar
(x=232 at 1280), and once hidden it was in the title bar after the magpie
(Mac x=175; Windows 14; Linux 93/14/40 as the brand folds). Each click
moved it.

Now #sideToggle is first in the title bar in both layouts, as Finder's,
Notes' and Mail's: layoutNav moves it with the brand, into .side-top when
the sidebar shows and to the front of .top when it doesn't. .side-top has
the header's height and left padding (Mac: after the traffic lights at
96px/zoom, as .top), so the button keeps its x, y and size. A sidebar too
narrow for the name keeps the bird (fitTop sets .side-top.tight). Windows'
10px .side-top is gone: the button needs that row there too. Nothing else
in the sidebar changed.

Run (on mote, through mote-run; NODE_PATH playwright 1.62.0, chromium and
webkit):
- Repro before the fix: a probe at 1280/900/640, en/zh/de, Mac/Windows/
  Linux chrome, gave the positions above.
- side-toggle.test.cjs gains "<os>: the button stays where it was" for
  Mac, Windows and Linux: every language (en, zh, zh-TW, ja, de) at 1280,
  900, 640 and a 168px sidebar; hide then show, x/y/w/h within 0.5px, the
  header fits, .side-top doesn't overflow.
- Broken by hand: the new test against origin/main's assets fails all 3
  OS subtests in both engines (18 pass, 8 fail); reverting layoutNav's
  append/prepend fails them too.
- side-toggle, side-width, header-centre: 49 pass, 1 fail (header-centre
  webkit, the ResizeObserver page error, #3479; the same on the base).
- The 22 GUI files that touch the sidebar, brand or toggle
  (--test-concurrency=2): 335 pass, 11 fail: header-centre webkit (#3479)
  and mobile-web's desktop compare against HEAD~1, which moved on purpose.
- mobile-web.test.cjs: until BASE_REF has the move, its desktop compare
  leaves the button, the magpie and the header out of both pictures, like
  its other "until BASE_REF has it" cases. Run in a git checkout on mote
  with BASE_REF=HEAD~1: 30 pass, 0 fail in chromium and webkit.
- At the head rebased on 9e8c22dad: side-toggle.test.cjs 26 pass, 0 fail;
  go test -run TestCoreScriptBudget ./internal/gui ok (app.js 1,315,308 of
  1,315,316, no raise; a comment in fitTop cut to fit after the rebase).
- go test ./internal/gui: TestMainWindowCorners/macOS_26_SDK red, #3949
  (macOS 27 box), not this change.

Not run: the whole GUI suite (mote was busy with other sessions' full
suites, load 45-110); the real app on Windows and Linux (the probe used
their chrome classes in Playwright).
This commit is contained in:
yetone
2026-10-30 10:55:05 +08:00
parent d9459a5371
commit 4a4a90c237
5 changed files with 77 additions and 15 deletions
+9 -5
View File
@@ -364,13 +364,17 @@ body.side-nav { --side-w: 212px; padding-left: var(--side-w); }
@media (pointer: coarse) { .side-edge { right: -12px; width: 24px; } }
.side-edge:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }
body.side-drag, body.side-drag * { cursor: col-resize !important; user-select: none; }
.side-top { flex: none; display: flex; align-items: center; height: 46px; padding: 0 18px; }
/* its top is the title bar's left end: the sidebar's button (app.js
layoutNav), then the magpie, at the header's own height and left padding,
so the button is in the one place whether the sidebar shows or not, as
Finder's and Notes' is (ztf4080 on X) */
.side-top { flex: none; display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 18px 0 14px; }
.side-top .brand { font-size: 13.5px; }
/* a sidebar too narrow for the name keeps the bird (app.js fitTop) */
.side-top.tight .brand > span:not(.logo) { display: none; }
/* the traffic lights are the sidebar's top left, as in a Mac app's sidebar;
the magpie beside them, level with them (see .top above) */
body.window.mac .side-top { height: calc(50px / var(--zoom, 1)); padding: calc(2px / var(--zoom, 1)) 0 0 calc(90px / var(--zoom, 1)); }
/* Windows' title bar above already shows the icon and the name */
body.window:not(.mac):not(.linux):not(.web) .side-top { height: 10px; }
the button and the magpie beside them, level with them (see .top above) */
body.window.mac .side-top { height: calc(50px / var(--zoom, 1)); padding: calc(2px / var(--zoom, 1)) 0 0 calc(96px / var(--zoom, 1)); }
.side-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 10px; }
.side-foot { flex: none; max-height: 55%; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; padding: 8px 10px 10px; border-top: .5px solid var(--line-2); }
/* a short window's sidebar keeps no bar beside its pages: a thin one is laid
+7 -5
View File
@@ -23591,6 +23591,9 @@ matchMedia("(max-width: 760px), (pointer: coarse) and (max-width: 1024px)").addE
// further still when they don't fit (the 560px window at 150%).
function fitTop() {
const top = $(".top"), nav = $("#nav"), brand = $(".brand"), actions = $(".actions");
const st = $(".side-top");
st.classList.remove("tight");
st.classList.toggle("tight", st.scrollWidth > st.clientWidth);
// a phone's browser: the tabs have a row of their own (app.css), at their size;
// and beside the sidebar the header holds only where the reader is and the icons
if (phoneWeb() || sideNav()) { top.classList.remove("tight", "cramped", "inrow", "crowded", "packed"); return; }
@@ -23599,8 +23602,7 @@ function fitTop() {
// the buttons sit against the padding; under a page zoom (the text size)
// their edge can measure a hair past it, which isn't running off (#457)
if (a.right > top.getBoundingClientRect().right - parseFloat(getComputedStyle(top).paddingRight) + 0.5) return false;
// the sidebar's button, when shown, comes after the brand
const lead = $("#sideToggle")?.offsetParent ? $("#sideToggle") : brand;
const lead = brand.offsetParent ? brand : $("#sideToggle");
const left = lead.offsetParent ? lead.getBoundingClientRect().right
: top.getBoundingClientRect().left + parseFloat(getComputedStyle(top).paddingLeft);
if (!nav?.offsetParent) return left + 8 <= a.left;
@@ -23659,17 +23661,17 @@ function layoutNav() {
return;
}
layoutNav.done = true;
const side = $("#side"), nav = $("#nav"), brand = $(".brand"), prefs = $("#prefs");
const side = $("#side"), nav = $("#nav"), brand = $(".brand"), prefs = $("#prefs"), btn = $("#sideToggle");
document.body.classList.toggle("side-nav", on);
side.hidden = !on;
$("#crumb").hidden = !on;
if (on) {
side.querySelector(".side-top").append(brand);
side.querySelector(".side-top").append(btn, brand);
side.querySelector(".side-scroll").append(nav);
side.querySelector(".side-foot").prepend(prefs);
nav.querySelector(":scope > .thumb")?.remove();
} else {
$(".top").prepend(brand);
$(".top").prepend(btn, brand);
$("#crumb").after(nav);
$(".actions").insertBefore(prefs, $("#winclose"));
}
File diff suppressed because one or more lines are too long
+9
View File
@@ -378,6 +378,15 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await current.addStyleTag({ content: ".row.pref .sub { white-space: nowrap; overflow-wrap: normal; }" });
await current.waitForTimeout(350);
}
// The sidebar's button sits ahead of the magpie in both layouts
// (ztf4080 on X), so the header beside the sidebar no longer
// starts with it: until BASE_REF has it, the button, the magpie
// and the header beside the sidebar are left out of both pictures and the rest
// compared as ever; side-toggle.test.cjs covers where they are.
if (!baselineFile("app.js").includes("append(btn, brand)")) {
for (const p of [current, original]) await p.addStyleTag({ content: "#sideToggle, .brand, body.side-nav .top { visibility: hidden !important; }" });
await current.waitForTimeout(350);
}
const before = PNG.sync.read(await still(original));
const after = PNG.sync.read(await still(current));
const sameSize = before.width === after.width && before.height === after.height;
+45
View File
@@ -143,6 +143,51 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await context.close();
});
// the button is in the one place whether the sidebar shows or not, as
// Finder's and Notes' is: it hid the sidebar from the sidebar's top and
// came back elsewhere, after the magpie (ztf4080 on X: "收起按钮在左上角,
// 但是收起后展开按钮变了"). Each title bar, wide and narrow, every language
// and the sidebar at its narrowest
for (const [os, platform] of [["Mac", "MacIntel"], ["Windows", "Win32"], ["Linux", "Linux x86_64"]]) {
await t.test(`${os}: the button stays where it was`, async () => {
for (const lang of Object.keys(words)) for (const [width, sideW] of [[1280, 0], [900, 0], [640, 0], [1280, 168]]) {
const context = await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.addInitScript(([p, w]) => {
Object.defineProperty(Navigator.prototype, "platform", { get: () => p });
localStorage.setItem("magpie.navLayout", "side");
if (w) localStorage.setItem("magpie.sideWidth", String(w));
}, [platform, sideW]);
await page.route("**/*", serve(lang));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
await frame(page);
const at = `${lang} ${width}${sideW ? ` sidebar ${sideW}` : ""}`;
const btn = page.locator("#sideToggle");
const place = () => btn.evaluate((b) => { const r = b.getBoundingClientRect(); return { x: r.left, y: r.top, w: r.width, h: r.height }; });
assert.ok(await side(page), at);
const shown = await place();
// the sidebar's top holds it and the magpie, nothing running over its edge
assert.ok(await btn.evaluate((b) => !!b.closest("#side .side-top")), `${at}: in the sidebar's top`);
assert.ok(await page.evaluate(() => { const s = document.querySelector(".side-top"); return s.scrollWidth <= s.clientWidth; }), `${at}: the sidebar's top fits`);
assert.ok(shown.x + shown.w <= (await page.locator("#side").boundingBox()).width, `${at}: inside the sidebar`);
for (const want of [false, true]) {
await btn.click();
await page.waitForFunction((w) => document.body.classList.contains("side-nav") === w, want);
await frame(page);
const now = await place();
for (const k of ["x", "y", "w", "h"]) assert.ok(Math.abs(now[k] - shown[k]) <= 0.5, `${at}: ${want ? "shown again" : "hidden"}, the button moved: ${JSON.stringify(shown)} -> ${JSON.stringify(now)}`);
if (!want) await headerFits(page);
}
assert.deepEqual(errors, [], at);
await context.close();
}
});
}
await t.test("the two trade places as one motion", async () => {
const context = await browser.newContext({ viewport: { width: 1280, height: 760 } });
const page = await context.newPage();