library: typing with an input method no longer moves the page (#2636)
In Library -> Instructions, typing Chinese through an input method made the
page jump up or down while a word was composed. The cause: the textarea's
autosize set height:auto to measure scrollHeight, so the page went short for
a moment and the browser clamped the view's scrollTop. Putting the height
back doesn't undo a clamp. app.js's scroll guard took the clamp for a scroll
the reader didn't make, and its scrollIntoView({block:"nearest"}) pulled a
textarea taller than the view to one of its edges. Every composition step is
an input, so this happened on every keystroke.
autosize (the only one in the GUI, used by a set's text, an agent's own
text, a skill's description and subagent boxes) now holds the textarea's
parent at its height while measuring, so the page never goes short.
What was run:
- New internal/gui/tests/library-ime-scroll.test.cjs covers en/zh, 980/560px,
a Default set's text and Cline's own text. Chromium composes through CDP
Input.imeSetComposition/insertText. WebKit gets synthetic
composition events and inputs.
- With the fix: 9/9 in both engines, before and after rebasing onto f191d6423.
- With client.js reverted by hand: red in both engines (4 of 9), set:default
in every lang/width; the page went e.g. 1000 -> 862, 1401, 1634.
- extra:cline wasn't red on main: its clamp is put back before paint. It
stays as a sibling guard.
- library-row-open-scroll and library-instr-sets pass in both engines.
- The whole GUI suite ran in both engines at concurrency 6, load ~150-300.
- Chromium: 5408/5519. WebKit: 5442/5547.
- Failed files were rerun at concurrency 2 and on unmodified main
(c1e95f919). All are red on main too and already filed (codex-predictions
#2624, segs-glide/lightweight #2683, provider-advanced-fold #2710,
tray-cell-click #2686, removed-groups-menu-scroll #2172/#2211, others as
filed).
- WebKit plugin-moved-signin and update-release-page passed alone.
removed-groups-menu-scroll went 4/4 three times. No library file
stayed red.
- gofmt -l: clean. go vet: darwin, and GOOS=linux and GOOS=windows with
-tags nogui: clean.
- go test -timeout 45m ./... under pipefail in a sandbox HOME: exit 0.
Not tried: a real system input method (macOS Pinyin) in the real app. Only
CDP and synthetic composition were used.
This commit is contained in:
@@ -355,6 +355,7 @@ covers it in both engines, every language and a narrow window.
|
||||
- Settings' Search APIs add row has a base URL field under the key for every API (#1580): the vendor's own address is its placeholder, picking an API already added fills in its saved URL so a new key alone keeps it, and Add with no key changes only the URL. See [a search API's base URL](gateway-routing.md#a-search-apis-base-url), [`renderSearch`](../../internal/gui/assets/app.js) and `search-api.test.cjs`.
|
||||
- Every user-visible string has zh, zh-TW, ja and de translations with the same placeholders. `gui-zh-tw.test.cjs`, `gui-ja.test.cjs` and `gui-de.test.cjs` fail on a missing one; `gui-zh-tw.test.cjs` also fails on a zh-TW string with a Simplified character left in it.
|
||||
- A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this. A click is taken where the reader left the view: a scroll not theirs made just before it, whose scroll event the browser sends only at the next frame, after the click, is put back first (`backToReader` in the click guard, #1554). What was clicked is held where it was (`hold`); a view at its top when clicked stays at its top, and what comes in above the control moves it down instead (#2134, `update-auto.test.cjs`), as long as it moves less than half its own height and so stays under the pointer. Anything larger above it, as the stage a day picked on Routing brings in above the bar, is scrolled past, and the control stays where it was clicked (`routing-days-fit.test.cjs`, `routing-failed-open.test.cjs`).
|
||||
- Typing never moves the page either. A textarea that grows with its text (the Library's `autosize` in plugins/library/client.js: a set's text, an agent's own text, a skill's description, a subagent's fields) is measured at height auto with what holds it kept at its height, so the page never goes short for a moment: a page gone short has its view's scroll clamped by the browser at every input, an input method's every composing step included, and the guard's putting it back pulled a textarea taller than the view to one of its edges (#2636, `library-ime-scroll.test.cjs`).
|
||||
- There are no native `<select>` elements and no colored left-border stripes. State is shown with a dot or a swatch.
|
||||
- The Usage page's cards and the tray panel's Allowances tab share one order, `settings.UsageOrder` (`byUsageOrder`). In the panel a balance-only card stands where that order puts it, and balances next to each other share one *Balances* grid (`panelBalances`, #1510); none is gathered after the plans. The panel's *Arrange* (`panelArrange`) moves rows in it and hides subscriptions from that tab alone (`settings.PanelUsageHidden`); both save through `POST /api/usage/arrange`, which changes only the field it is sent, and the Settings save keeps both. Hiding is display only: a menu bar cell's card shows though hidden (`panelPeek`). See `TestUsageArrangePanelHidden`, `panel-arrange.test.cjs` and `panel-balance-order.test.cjs`.
|
||||
- A client in the Usage page's Agents list can be hidden from that list (ikunbots on X): its row's "…" button or right-click opens the row menu with *Hide from this list*, saved by client id in `settings.UsageAgentsHidden` through the same `POST /api/usage/arrange` (`agentsHidden`), and kept by the Settings save. The ledger, the totals and the chart still count a hidden client. A quiet "{n} hidden" line under the list opens them, each with *Unhide* (`hideUsageAgent`). See `TestUsageArrangeAgentsHidden` and `usage-agents-hide.test.cjs`.
|
||||
|
||||
@@ -78,7 +78,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
go test -tags nogui ./internal/library -run 'TestReadLooksAtEachFolderOnce|TestLinkChangedBetweenVisitsShows|TestUnreadablePartIsLookedAtAgain|TestCheckSkillsFindsNewOnes|TestNewBase|TestUpdateKeeps|TestCheckDue|TestCheckSkillsMarksItDone|TestTargets|TestServer|TestImportServer|TestCheck|TestInstructions|TestInstructionsSetLinkedToAgentsFile|TestInstructionSets|TestTakesAlma|TestAlma|TestLinkedSet|TestLinkRefused|TestSkill|TestRemoveFoundSkill|TestInstallSet|TestInstallLists|TestEverySkillAgents|TestEveryServerAgents|TestSomeServersAgents|TestRemoveServers|TestRTK|TestEnvRefs|TestDshRefRoundTrip|TestDshImportKeepsJS|TestAgentMCPFiles|TestCodeBuddyMCPFile|TestZedMCP|TestOwnServerFromElsewhereRunsThisMagpie|TestUsersOwnServerStaysAsItIs|TestCarriedOwnServerIsEachComputersMagpie|TestCarry|TestPageReadDoesntReadUnchangedSkillsAgain|TestJustWrittenSkillIsReadAgain|TestUnreadableSkillIsntRememberedAsDifferent|TestGlanceLeavesOutTheAgentsSkills|TestPluginAgent|TestPluginMCPFormatsAreWritten|TestToolsOff|TestOffList|TestHooks|TestSubagent|TestCheckRenewsMagpiesSignIn|TestCheckSaysSignInRanOut|TestSignInAsTheUsersOwnApp|TestOAuthAppChecked|TestOAuthAppSecretCarried|TestGoneAgentListedToTakeOut'
|
||||
go test -race ./internal/mcpauth
|
||||
go test -tags nogui ./internal/library
|
||||
node --test internal/gui/tests/library-items.test.cjs internal/gui/tests/library-alma-profile.test.cjs internal/gui/tests/library-rtk-gain.test.cjs internal/gui/tests/library-rtk-nohook.test.cjs internal/gui/tests/library-servers-bulk.test.cjs internal/gui/tests/library-pick-remove.test.cjs internal/gui/tests/library-env-refs.test.cjs internal/gui/tests/library-zed-mcp.test.cjs internal/gui/tests/library-workbuddy-trust.test.cjs internal/gui/tests/skill-new-in-repo.test.cjs internal/gui/tests/skill-update-edited.test.cjs internal/gui/tests/remove-found-skill.test.cjs internal/gui/tests/found-skill-pick-remove.test.cjs internal/gui/tests/library-loading.test.cjs internal/gui/tests/library-mcp-tools.test.cjs internal/gui/tests/library-mcp-tool-switch.test.cjs internal/gui/tests/library-hooks.test.cjs internal/gui/tests/library-subagents.test.cjs internal/gui/tests/library-mcp-health.test.cjs internal/gui/tests/mcp-signin-health.test.cjs internal/gui/tests/mcp-signin.test.cjs internal/gui/tests/mcp-editor-cancel.test.cjs internal/gui/tests/mcp-oauth-app.test.cjs
|
||||
node --test internal/gui/tests/library-items.test.cjs internal/gui/tests/library-alma-profile.test.cjs internal/gui/tests/library-rtk-gain.test.cjs internal/gui/tests/library-rtk-nohook.test.cjs internal/gui/tests/library-servers-bulk.test.cjs internal/gui/tests/library-pick-remove.test.cjs internal/gui/tests/library-env-refs.test.cjs internal/gui/tests/library-zed-mcp.test.cjs internal/gui/tests/library-workbuddy-trust.test.cjs internal/gui/tests/skill-new-in-repo.test.cjs internal/gui/tests/skill-update-edited.test.cjs internal/gui/tests/remove-found-skill.test.cjs internal/gui/tests/found-skill-pick-remove.test.cjs internal/gui/tests/library-loading.test.cjs internal/gui/tests/library-mcp-tools.test.cjs internal/gui/tests/library-mcp-tool-switch.test.cjs internal/gui/tests/library-hooks.test.cjs internal/gui/tests/library-subagents.test.cjs internal/gui/tests/library-mcp-health.test.cjs internal/gui/tests/mcp-signin-health.test.cjs internal/gui/tests/mcp-signin.test.cjs internal/gui/tests/mcp-editor-cancel.test.cjs internal/gui/tests/mcp-oauth-app.test.cjs internal/gui/tests/library-ime-scroll.test.cjs
|
||||
```
|
||||
|
||||
The package's `TestMain` runs in a home of its own (`testenv`), never the
|
||||
|
||||
@@ -1102,8 +1102,19 @@ magpie.plugin("library", (ctx) => {
|
||||
|
||||
// ---------- instructions ----------
|
||||
|
||||
// Measured at height auto, the textarea is short for a moment. What holds
|
||||
// it is held at its height meanwhile, so the page never is: a page gone
|
||||
// short has its view's scroll clamped by the browser, which no height put
|
||||
// back undoes, and an input method's every keystroke is an input (#2636:
|
||||
// the page jumped while a word was composed).
|
||||
function autosize(ta, min) {
|
||||
const fit = () => { ta.style.height = "auto"; ta.style.height = Math.max(min, ta.scrollHeight + 2) + "px"; };
|
||||
const fit = () => {
|
||||
const box = ta.parentElement, was = box?.style.minHeight;
|
||||
if (box) box.style.minHeight = box.offsetHeight + "px";
|
||||
ta.style.height = "auto";
|
||||
ta.style.height = Math.max(min, ta.scrollHeight + 2) + "px";
|
||||
if (box) box.style.minHeight = was;
|
||||
};
|
||||
ta.addEventListener("input", fit);
|
||||
// fitted once it's on the page, before it's painted, so what's under it
|
||||
// doesn't move a frame later
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// #2636: in Library → Instructions, typing with a Chinese input method made
|
||||
// the page jump up or down while a word was being composed. Each step of a
|
||||
// composition is an input, and the textarea's autosize set its height to
|
||||
// auto to measure it: the page went short for a moment, the browser clamped
|
||||
// the view's scroll to the shorter page, and the scroll guard's putting it
|
||||
// back pulled the textarea, taller than the view, to one of its edges. The
|
||||
// page stays where it is while a word is composed and committed, in the
|
||||
// Default set's text near the page's foot and in an agent's own text at the
|
||||
// very foot. Chromium composes through its input-method protocol
|
||||
// (Input.imeSetComposition); WebKit, which has none, gets the composition's
|
||||
// events and inputs as an input method sends them. English and Chinese, wide
|
||||
// and narrow; 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 ids = ["claude", "codex", "gemini", "opencode", "pi", "kimi", "qwen", "droid", "crush", "goose", "amp", "cline"];
|
||||
const named = (id) => id[0].toUpperCase() + id.slice(1);
|
||||
const lines = (n, what) => Array.from({ length: n }, (_, i) => `- ${what} ${i + 1}: keep it short`).join("\n");
|
||||
const library = () => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: ids.map((id) => ({ id, name: named(id), icon: "", instructions: `${HOME}/.${id}/AGENTS.md` })),
|
||||
instructions: {
|
||||
shared: "",
|
||||
sets: [{ id: "default", name: "", active: true, text: lines(60, "rule") }],
|
||||
agents: ids.map((id) => ({ agent: id, name: named(id), icon: "", path: `${HOME}/.${id}/AGENTS.md`, on: true, extra: id === "cline" ? lines(10, "note") : "" })),
|
||||
},
|
||||
foundServers: [], projects: [], foundSkills: [], skills: [], servers: [],
|
||||
});
|
||||
|
||||
function server(lang) {
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light" } } });
|
||||
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
|
||||
if (url.pathname === "/api/library") return route.fulfill({ json: library() });
|
||||
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
|
||||
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
|
||||
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
|
||||
if (url.pathname.startsWith("/api/")) return route.fulfill({ 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 view = "#view-library";
|
||||
// pinyin as it is typed, then the word picked
|
||||
const words = [["n", "ni", "nih", "niha", "nihao"], "你好", ["s", "sh", "shi", "shij", "shiji", "shijie"], "世界"];
|
||||
|
||||
// A word composed and committed at the caret, as an input method does it.
|
||||
async function compose(page, engine, cdp, ta) {
|
||||
for (let i = 0; i < words.length; i += 2) {
|
||||
if (engine === "chromium") {
|
||||
for (const p of words[i]) {
|
||||
await cdp.send("Input.imeSetComposition", { text: p, selectionStart: p.length, selectionEnd: p.length });
|
||||
await page.waitForTimeout(40);
|
||||
}
|
||||
await cdp.send("Input.insertText", { text: words[i + 1] });
|
||||
await page.waitForTimeout(40);
|
||||
continue;
|
||||
}
|
||||
await ta.evaluate((e) => {
|
||||
e.dispatchEvent(new CompositionEvent("compositionstart", { bubbles: true, data: "" }));
|
||||
e.dataset.from = e.selectionStart;
|
||||
e.dataset.len = 0;
|
||||
});
|
||||
const step = (data, done) => ta.evaluate((e, [data, done]) => {
|
||||
const from = +e.dataset.from;
|
||||
e.setRangeText(data, from, from + +e.dataset.len, "end");
|
||||
e.dataset.len = data.length;
|
||||
if (!done) e.dispatchEvent(new CompositionEvent("compositionupdate", { bubbles: true, data }));
|
||||
e.dispatchEvent(new InputEvent("input", { bubbles: true, data, inputType: done ? "insertFromComposition" : "insertCompositionText", isComposing: !done }));
|
||||
if (done) e.dispatchEvent(new CompositionEvent("compositionend", { bubbles: true, data }));
|
||||
}, [data, done]);
|
||||
for (const p of words[i]) { await step(p, false); await page.waitForTimeout(40); }
|
||||
await step(words[i + 1], true);
|
||||
await page.waitForTimeout(40);
|
||||
}
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": composing a word in the Library's instructions leaves the page where it is", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const errors = [];
|
||||
t.after(async () => {
|
||||
if (errors.length) console.log(errors);
|
||||
await browser.close();
|
||||
});
|
||||
for (const lang of ["en", "zh"]) for (const width of [980, 560]) for (const field of ["set:default", "extra:cline"]) {
|
||||
await t.test(`${lang}, ${width}px wide, ${field}`, async () => {
|
||||
const ctx = await browser.newContext({ viewport: { width, height: 640 }, reducedMotion: "reduce" });
|
||||
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "instructions"); } catch {} });
|
||||
const page = await ctx.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang));
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.locator('button[data-view="library"]').click();
|
||||
await page.locator(`${view} .lib-set`).first().click();
|
||||
await page.locator(`${view} textarea[data-lib="set:default"]`).waitFor();
|
||||
await page.waitForTimeout(300);
|
||||
const v = page.locator(view);
|
||||
const ta = page.locator(`${view} textarea[data-lib="${field}"]`);
|
||||
const wheel = async (n) => { for (let i = 0; i < n; i++) { await page.mouse.move(width / 2, 320); await page.mouse.wheel(0, 200); await page.waitForTimeout(20); } };
|
||||
if (field === "set:default") {
|
||||
// down by the wheel till the set's last lines, and the caret at
|
||||
// their end, are in sight
|
||||
for (let i = 0; i < 60; i++) {
|
||||
const [bottom, foot] = await ta.evaluate((e) => [e.getBoundingClientRect().bottom, e.closest(".view").getBoundingClientRect().bottom]);
|
||||
if (bottom < foot - 60) break;
|
||||
await wheel(1);
|
||||
}
|
||||
} else {
|
||||
// Cline's own text, open at the foot of the page
|
||||
await wheel(30);
|
||||
await page.waitForTimeout(300);
|
||||
const row = page.locator(`${view} .lib-row:not(.lib-set)`).filter({ hasText: "Cline" }).first();
|
||||
const b = await row.boundingBox();
|
||||
await page.mouse.click(b.x + 80, b.y + b.height / 2);
|
||||
await ta.waitFor();
|
||||
await page.waitForTimeout(300);
|
||||
await wheel(10); // to the new foot, the click's hold let go of
|
||||
}
|
||||
await page.waitForTimeout(400);
|
||||
const before = await v.evaluate((e) => e.scrollTop);
|
||||
assert(before > 100, "the page didn't scroll down: " + before);
|
||||
// the caret at the text's end, in sight
|
||||
await ta.evaluate((e) => { e.focus({ preventScroll: true }); e.setSelectionRange(e.value.length, e.value.length); });
|
||||
const caret = await ta.evaluate((e) => {
|
||||
const r = e.getBoundingClientRect(), b = e.closest(".view").getBoundingClientRect();
|
||||
return [r.bottom, b.top, b.bottom];
|
||||
});
|
||||
assert(caret[0] > caret[1] && caret[0] < caret[2], `the text's end isn't in sight: ${caret}`);
|
||||
await page.evaluate(() => {
|
||||
const v = document.querySelector("#view-library");
|
||||
window.__seen = [];
|
||||
const look = () => window.__seen?.push(v.scrollTop);
|
||||
v.addEventListener("scroll", look, { passive: true });
|
||||
(function frame() { look(); if (window.__seen) requestAnimationFrame(frame); })();
|
||||
});
|
||||
const cdp = engine === "chromium" ? await ctx.newCDPSession(page) : null;
|
||||
await compose(page, engine, cdp, ta);
|
||||
await page.waitForTimeout(400);
|
||||
const seen = await page.evaluate(() => { const s = window.__seen; window.__seen = null; return s; });
|
||||
assert.match(await ta.inputValue(), /你好世界$/, "the words weren't typed");
|
||||
const moved = seen.filter((s) => Math.abs(s - before) > 1);
|
||||
assert.deepEqual(moved, [], `the page moved while a word was composed, from ${before} (the page went to ${[...new Set(moved)].join(", ")})`);
|
||||
await ctx.close();
|
||||
});
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user