Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gui: a model chip picked or unpicked keeps its size (frankdeng on Discord)

yetone084c2275d1d5
diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css
index 21ed6897d..2ef04d21c 100644
--- a/internal/gui/assets/app.css
+++ b/internal/gui/assets/app.css
@@ -3038,7 +3038,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
.mbulk { display: flex; align-items: center; gap: 6px; }
.mbulk > input { max-width: 260px; flex: 1; }
/* a long list scrolls on its own, not the editor with it past its ends */
-.mchips { display: flex; flex-wrap: wrap; gap: 4px; max-height: min(132px, 28vh); overflow-y: auto; overscroll-behavior: contain; padding: 1px; }
+.mchips { display: flex; flex-wrap: wrap; gap: 4px; max-height: min(240px, 40vh); overflow-y: auto; overscroll-behavior: contain; padding: 1px; }
.mchips::-webkit-scrollbar { width: 0; }
/* let out to its full height (#833): the editor's body scrolls instead */
.mchips.open { max-height: none; overflow-y: visible; }
@@ -3064,6 +3064,15 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
.mchip:hover { color: var(--fg); border-color: var(--muted); }
.mchip.on { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); font-weight: 500; }
.mchip.on::before { content: "✓"; font-size: 10px; }
+/* a chip a click picks and unpicks keeps its size either way (frankdeng on
+ Discord: the tick, and the bolder name, widened a chip as it was picked,
+ and every chip after it moved under the pointer). Its tick has a place
+ of its own, as a menu's check column has, held empty while unpicked, and
+ a pick is said by the tick and the colour, the weight left as it is. */
+.mchip.pick { padding-left: 7px; }
+.mchip.pick::before { content: "✓"; font-size: 10px; margin-right: -1px; visibility: hidden; }
+.mchip.pick.on { font-weight: inherit; }
+.mchip.pick.on::before { visibility: visible; }
/* what tells a model from others of the same name (modelTells): quiet,
after the name, never in the accent of a pick */
.mchip .mtell { color: var(--muted); font-weight: 400; font-size: 10.5px; }
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index f5df7b4da..e48f9b8c6 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -10443,7 +10443,7 @@ function addFormModels(ex) {
const on = draft.extra.includes(m.id);
// past the first 120 only the picked are drawn, till the rest are asked for
if (shown >= 120 && !f && !showAll && !on) { hidden++; continue; }
- const c = el("button", "mchip" + (on ? " on" : ""));
+ const c = el("button", "mchip pick" + (on ? " on" : ""));
c.append(el("span", "", m.name || m.id));
const tell = tellTag(tells.get(m.id));
if (tell) c.append(tell);
@@ -10694,9 +10694,9 @@ const servedIds = (p) => draft.chosen.length ? draft.chosen : draft.none ? [] :
// modelsOpen: a provider editor's models let out to their full height
// (#833), kept for the next editor opened. MCHIPS_MAX: the most the box is
-// tall held, as app.css's .mchips max-height: min(132px, 28vh) says
+// tall held, as app.css's .mchips max-height: min(240px, 40vh) says
let modelsOpen = false;
-const MCHIPS_MAX = 132;
+const MCHIPS_MAX = 240;
// emptyModelsHint is what an empty model list says. Azure OpenAI's is its
// deployments, asked for with the key after it is added (#1995): while that
// is under way it says so, and after it says the deployments' names are
@@ -10852,7 +10852,7 @@ function renderModels(p) {
// Held, the box is MCHIPS_LINES tall (app.css .mchips); open, it is as
// tall as its chips, which must be more than that to fold
requestAnimationFrame(() => {
- const most = Math.min(MCHIPS_MAX, innerHeight * 0.28);
+ const most = Math.min(MCHIPS_MAX, innerHeight * 0.4);
fold.hidden = !(chips.scrollHeight > (modelsOpen ? most : chips.clientHeight) + 1);
});
};
@@ -10878,7 +10878,7 @@ function renderModels(p) {
// asked for: a picked model is never out of sight (#685: 10 picked,
// 7 shown, and "4 more, filter to find them" with no names to filter by)
if (shown >= 80 && !f && !showAll && !on) { hidden++; continue; }
- const c = el("button", "mchip" + (on ? " on" : served.has(m.id) ? " auto" : "") + (noAPI(m) ? " noapi" : ""));
+ const c = el("button", "mchip pick" + (on ? " on" : served.has(m.id) ? " auto" : "") + (noAPI(m) ? " noapi" : ""));
c.append(el("span", "", m.name && m.name !== m.id ? m.name : m.id));
const tell = tellTag(tells.get(m.id));
if (tell) c.append(tell);
@@ -13953,7 +13953,7 @@ function accountModels(p, ref, isKey, name) {
for (const id of ids) {
const m = p.models.find((x) => x.id === id);
const on = acctModels.chosen.includes(id);
- const c = el("button", "mchip" + (on ? " on" : ""));
+ const c = el("button", "mchip pick" + (on ? " on" : ""));
c.append(el("span", "", m?.name && m.name !== id ? m.name : id));
const tell = tellTag(tells.get(id));
if (tell) c.append(tell);
diff --git a/internal/gui/tests/model-chip-steady.test.cjs b/internal/gui/tests/model-chip-steady.test.cjs
new file mode 100644
index 000000000..8f836631f
--- /dev/null
+++ b/internal/gui/tests/model-chip-steady.test.cjs
@@ -0,0 +1,100 @@
+// Run with Node's test runner and Playwright on the module path; see README.md.
+// frankdeng on Discord: "点击某个模型,还会因为选中状态导致排版有变化,位置
+// 发生偏移". A pick drew a tick before the name and set it bolder, so the
+// chip grew, and every chip after it on the row, and the rows under it,
+// moved under the pointer. A chip that a click picks and unpicks now keeps
+// its place for its tick, and a pick no longer changes the weight: no chip
+// in the provider editor's list moves or changes size when one is picked,
+// unpicked, or picked first out of none picked (#681's path, which flips
+// every served chip at once). Chromium and WebKit, wide and narrow, in
+// every language; 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 fetched = new Date(Date.now() - 3600e3).toISOString();
+const names = ["DeepSeek V4", "DeepSeek V4 Flash", "Kimi K3", "GLM 5.3", "Qwen 4 Max", "MiniMax M3", "Doubao Seed 2.5 Pro", "Claude Sonnet 5", "GPT-5.5", "Gemini 3.5 Pro"];
+const models = Array.from({ length: 30 }, (_, i) => {
+ const name = names[i % names.length] + (i >= names.length ? ` ${Math.floor(i / names.length) + 1}` : "");
+ return { id: name.toLowerCase().replaceAll(" ", "-"), name, rate: i % 3 ? 0.1 : undefined };
+});
+
+function serve(lang, chosen) {
+ const provider = () => {
+ const on = new Set(chosen.length ? chosen : models.map((m) => m.id));
+ return {
+ id: "relay", name: "Relay", icon: "generic", host: "", chat: "https://relay.example.com/v1", responses: "", anthropic: "", catalog: "",
+ models: models.map((m) => ({ ...m, on: on.has(m.id) })), chosen, fetched, agents: [], fallback: [], headers: {},
+ key: { set: true, masked: "sk-…one" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", ready: true,
+ };
+ };
+ return async (route) => {
+ const req = route.request(), url = new URL(req.url());
+ const json = (data) => route.fulfill({ json: data });
+ 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 json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
+ if (url.pathname === "/api/plugins") return json({ plugins: [] });
+ if (url.pathname === "/api/providers") return json({ providers: [provider()], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
+ if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
+ if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
+ 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)];
+ try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
+ };
+}
+
+const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
+const cases = [...LANGS.map((lang) => [lang, 900]), ...LANGS.map((lang) => [lang, 420])];
+
+for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
+ for (const [lang, width] of cases) {
+ test(`${engine} ${lang} ${width}px: a model chip picked or unpicked moves no chip`, async (t) => {
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ t.after(() => browser.close());
+ for (const [label, chosen] of [["some picked", models.filter((_, i) => i % 2 === 0).map((m) => m.id)], ["none picked", []]]) {
+ await t.test(label, async () => {
+ const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
+ page.setDefaultTimeout(5000);
+ const errors = [];
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.route("**/*", serve(lang, chosen));
+ await page.goto("http://magpie.test/?view=providers");
+ const editor = page.locator("#modal:not([hidden]) .editor");
+ await page.locator(".row.provider", { hasText: "Relay" }).first().click();
+ const chips = editor.locator(".mchips .mchip");
+ await chips.first().waitFor();
+ // each chip's box within the list's own content, so that a scroll
+ // of the page or the list (the click brings a chip into view at
+ // 420px) is not counted as a chip moving
+ const rects = () => chips.evaluateAll((cs) => {
+ const list = cs[0].parentElement, l = list.getBoundingClientRect();
+ const r1 = (v) => Math.round(v * 10) / 10;
+ return cs.map((c) => { const r = c.getBoundingClientRect(); return [c.textContent, r1(r.x - l.x + list.scrollLeft), r1(r.y - l.y + list.scrollTop), r1(r.width), r1(r.height)]; });
+ });
+ const on = () => chips.evaluateAll((cs) => cs.filter((c) => c.classList.contains("on")).length);
+
+ const before = await rects();
+ assert.equal(before.length, models.length);
+ // a chip early in the list, so a change in its width would move
+ // the rest of its row and the rows under it
+ const target = chips.nth(1);
+ const was = await on();
+ await target.click();
+ assert.notEqual(await on(), was, "the click changed no pick");
+ assert.deepEqual(await rects(), before, "a chip moved or changed size as one was picked");
+ await target.click();
+ assert.deepEqual(await rects(), before, "a chip moved or changed size as one was unpicked");
+ await chips.nth(2).click();
+ assert.deepEqual(await rects(), before, "a chip moved or changed size on a second pick");
+ assert.deepEqual(errors, []);
+ await page.context().close();
+ });
+ }
+ });
+ }
+}
diff --git a/internal/gui/tests/model-first-pick.test.cjs b/internal/gui/tests/model-first-pick.test.cjs
index 97f59e9f9..a95f86239 100644
--- a/internal/gui/tests/model-first-pick.test.cjs
+++ b/internal/gui/tests/model-first-pick.test.cjs
@@ -90,7 +90,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
};
const chip = (n) => editor.locator(".mchips .mchip", { has: page.locator(`span:text-is("${n}")`) });
const picked = () => editor.locator(".mchips .mchip.on").evaluateAll((cs) => cs.map((c) => c.firstChild.textContent));
- const ticked = () => editor.locator(".mchips .mchip").evaluateAll((cs) => cs.filter((c) => getComputedStyle(c, "::before").content.includes("✓")).length);
+ const ticked = () => editor.locator(".mchips .mchip").evaluateAll((cs) => cs.filter((c) => { const b = getComputedStyle(c, "::before"); return b.content.includes("✓") && b.visibility === "visible"; }).length);
// untouched and saved: no picks written, as before
await open();
diff --git a/internal/gui/tests/provider-add-models.test.cjs b/internal/gui/tests/provider-add-models.test.cjs
index ca715b742..234eb5f9d 100644
--- a/internal/gui/tests/provider-add-models.test.cjs
+++ b/internal/gui/tests/provider-add-models.test.cjs
@@ -117,7 +117,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// a chip ticked is in the field; typing ticks a chip
await still(chips.nth(0), "a chip");
assert.equal(await field.inputValue(), "gpt-5.5");
- assert.equal(await chips.nth(0).getAttribute("class"), "mchip on");
+ assert.equal(await chips.nth(0).getAttribute("class"), "mchip pick on");
await field.fill("gpt-5.5, deepseek-v4, own-model");
assert.equal(await ed.locator('.add-models-list .mchip.on').count(), 2);
assert.equal(await ed.locator(".add-models-list .detect-acts .hint").textContent(), L.picked(2, 30));