From cf455ebd5f183f96bb2e72357b29bf5958f41bc3 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 14 Oct 2026 18:25:33 +0800 Subject: [PATCH] gui: a view at its top when a control is clicked stays at its top, what came in above moving the control down (#2134) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The click guard's own rule says "A view at its top stays at its top: what comes in above the control there moves it down instead of scrolling itself out of sight", but hold() only kept that rule for the room at the foot. Anything that grew above the held control scrolled the view to follow it. At 420 wide, Settings › About turning Automatic updates Off gave the Version row its "are off" line ~2.3px tall once the save answered, and the view slid from 0 to 2. hold() now keeps a view that was at its top (h.top) at 0, so the switch moves down by those pixels instead. Tests: - update-auto: a new case at 420x640 clicks Off with Settings at its top and checks scrollTop after the save's redraw (600ms), not only right after the click. On origin/main's app.js it is red in both engines (2 !== 0); with the change green. - update-restart (#2096) held the switch to within 1px, which is the old behaviour at the top. It now checks the at-top rule when the view is at its top (scrollTop 0, switch down by at most 4px), and the old 1px hold otherwise. Run (load avg 200-340 from other sessions): - update-auto + update-restart, chromium and webkit, widths 1100 and 420, en/zh/zh-TW/ja/de: 32/32. - 71 scroll-guard files (click-scroll, *scroll*, *steady*, *pin*, *profile*, settings*, stays-strict, held-animations, and every file checking "must not scroll the page"), both engines, 4 wide: 921 pass, 11 fail. The fails are nav-sub-unroll, removed-groups-menu-scroll, settings-proxy-auth and text-size. Alone, settings-proxy-auth passes 10/10 and nav-sub-unroll chromium 2 of 2; nav-sub-unroll webkit, removed-groups-menu-scroll and text-size are red alone on origin/main bda271999's app.js too (#1950, #1866, filed #2172). Not tried: the real app window; only the Playwright engines. --- internal/gui/assets/app.js | 5 ++++ internal/gui/tests/update-auto.test.cjs | 29 ++++++++++++++++++++++ internal/gui/tests/update-restart.test.cjs | 12 ++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 4c68fb783..6ec678f5a 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -24225,6 +24225,11 @@ function hold(h) { if (Math.abs(d) >= 1) { let want = v.scrollTop + d; const max = v.scrollHeight - v.clientHeight; + // a view at its top when clicked stays at its top: what comes in above + // what was clicked moves it down rather than scrolling the view to follow + // it. Turning automatic updates off grew the Version row above the + // switch once the save answered, and the view slid 2px off its top (#2134) + if (h.top && want > 0) want = 0; // a view at its top when clicked stays there rather than be given room // to scroll down: a chip saved in the panel's Profiles came in above the // button held, and room made for the button slid the chip up under the diff --git a/internal/gui/tests/update-auto.test.cjs b/internal/gui/tests/update-auto.test.cjs index bd8050a27..f3c0eb3b8 100644 --- a/internal/gui/tests/update-auto.test.cjs +++ b/internal/gui/tests/update-auto.test.cjs @@ -164,6 +164,35 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await scrolls(page), before, "the click must not scroll the page"); assert.deepEqual(errors, []); }); + + // A view at its top stays at its top (#2134): at 420 wide Settings + // scrolls, and turning updates off gives the Version row above the + // switch its "are off" line once the save answers. That moves the + // switch down; it must not scroll the view, then or after the redraw. + await t.test(lang + ": 420 wide at the top, Off moves the switch down, not the page", async () => { + const ctl = { off: false, every: 0, state: "", checks: 0, saves: [] }; + const errors = []; + const page = await (await browser.newContext({ viewport: { width: 420, height: 640 } })).newPage(); + page.setDefaultTimeout(5000); + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, ctl)); + await watchSettingsReads(page); + await page.goto("http://magpie.test/?view=settings"); + await settingsDrawn(page); + await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click(); + await page.locator("#setPage-about").waitFor({ state: "visible" }); + const auto = page.locator("#about .row.pref", { has: page.locator(".name", { hasText: new RegExp("^" + w.auto + "$") }) }); + await auto.waitFor(); + await page.waitForTimeout(300); + const view = page.locator("#view-settings"); + assert.equal(await view.evaluate((v) => v.scrollTop), 0); + assert.ok(await view.evaluate((v) => v.scrollHeight > v.clientHeight + 10), "Settings must be able to scroll at 420"); + await auto.locator(".opt", { hasText: w.off }).click(); + await page.locator("#about .sub", { hasText: w.isOff }).waitFor(); + await page.waitForTimeout(600); // past the save's redraw and the switch's play + assert.equal(await view.evaluate((v) => v.scrollTop), 0, "a view at its top stays at its top"); + assert.deepEqual(errors, []); + }); } }); } diff --git a/internal/gui/tests/update-restart.test.cjs b/internal/gui/tests/update-restart.test.cjs index 00b4254ad..6e26fb721 100644 --- a/internal/gui/tests/update-restart.test.cjs +++ b/internal/gui/tests/update-restart.test.cjs @@ -148,9 +148,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // automatic updates off: kept, dimmed, says when it works // (the version row above then says automatic updates are off, a // line that can grow it by a pixel or two: what is held is the - // control clicked, where it is on the screen; at the view's top - // WebKit scrolls it by those pixels, #2134) + // control clicked, where it is on the screen, unless the view is at + // its top, which stays at its top and lets the switch move down by + // those pixels, #2134) await showRow(page, auto); + const settings = page.locator("#view-settings"); + const atTop = await settings.evaluate((v) => v.scrollTop < 1); const y0 = (await auto.locator(".opt").nth(0).boundingBox()).y; await auto.locator(".opt").nth(0).click(); await restart.locator(".sub", { hasText: w.whileOn }).waitFor(); @@ -159,7 +162,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(ctl.saves.at(-1).autoRestart, true); await page.waitForTimeout(400); const y1 = (await auto.locator(".opt").nth(0).boundingBox()).y; - assert.ok(Math.abs(y1 - y0) <= 1, `the clicked switch moved ${y1 - y0}px`); + if (atTop) { + assert.equal(await settings.evaluate((v) => v.scrollTop), 0, "a view at its top stays at its top"); + assert.ok(y1 - y0 >= -1 && y1 - y0 <= 4, `the clicked switch moved ${y1 - y0}px`); + } else assert.ok(Math.abs(y1 - y0) <= 1, `the clicked switch moved ${y1 - y0}px`); // and off again await showRow(page, restart);