gui: a setting's hint card starts at the pointer, not at the row's name (mmmg_btc on X)

Resting the pointer on Settings › About's 更新内容 row put the hint at the
far left of the row. 5710283da lined its text up with the row's name; the
pointer is what asked, so settingshints.js now keeps the pointer's x and a
card the pointer asked starts there (12px left of it, kept 16px inside the
window), with its grow-from origin at the pointer. A card a key asked
(focus) still lines up with the name. Every row hint comes through this one
module (Settings, a provider editor's fields, Routing groups), so they all
behave the same; native titles already show at the pointer.

Run on mote: provider-prefs-layout (card at the pointer; red on the old
code, 5 of 10), editor-hints, settings-hints (its pointer and key checks
changed), searcher-pick, settings-lines-wrap, sign-in-moves, and the gui-*
and i18n-* files, chromium and webkit; TestCoreScriptBudget; gofmt.
Reds: settings-hints "Settings' explanations show on hover and focus"
(chromium and webkit) fails the same way on base before reaching the
changed lines ("the card doesn't say the row's line"), and editor-hints in
webkit ("Tab didn't come back") fails on base too; both are filed.
Not tried: a live Mac window.
This commit is contained in:
yetone
2026-11-11 04:45:46 -08:00
parent ab5824aeea
commit 16ed1a9524
8 changed files with 199 additions and 5 deletions
+6
View File
@@ -461,6 +461,12 @@ body.side-nav #prefs svg { flex: none; width: 15px; height: 15px; margin: 0 .5px
text's own ink; the accent is kept for what acts */
body.side-nav :is(#nav button.on .nav-ic, #prefs.on svg) { color: var(--fg); }
body.side-nav .side-l { display: inline; }
body.side-nav #nav > button[data-plugin-page] { position: relative; }
body.side-nav #nav > button[data-plugin-page]::before { content: ""; position: absolute; left: 2px; top: 50%; width: 6px; height: 11px; margin-top: -5.5px; background: radial-gradient(circle, var(--muted) .9px, transparent 1.2px) 0 0 / 3px 3.75px; opacity: 0; transition: opacity .15s; }
body.side-nav #nav > button[data-plugin-page]:is(:hover, .dragging)::before { opacity: 1; }
#nav.sorting { user-select: none; -webkit-user-select: none; }
#nav.sorting > button[data-plugin-page] { transition: transform .22s cubic-bezier(.22, 1, .36, 1); }
#nav > button[data-plugin-page].dragging { position: relative; z-index: 2; background: var(--card); box-shadow: 0 6px 18px rgba(20, 22, 30, .12), 0 0 0 1px var(--line); transition: none; }
body.side-nav #nav button.has-dot::after { top: 50%; right: 10px; margin-top: -3px; width: 6px; height: 6px; }
/* the open page's tabs, under it on a thin line */
.nav-sub { position: relative; display: flex; flex-direction: column; gap: 1px; margin: 2px 0 6px 16px; padding-left: 8px; }
+32 -1
View File
@@ -203,10 +203,41 @@
b.append(s);
}
b.append(el("span", "", titled(e)));
b.onclick = () => { show(e.key); b.blur(); };
b.onclick = () => { if (b.dataset.dragged) return; show(e.key); b.blur(); };
b.addEventListener("pointerdown", (ev) => hold(b, ev));
return b;
}
// a press held 400ms on a tab picks it up; it is dragged to its place
// and the order kept (settings PluginPageOrder)
function hold(b, ev) {
if (ev.button !== 0 || !document.body.classList.contains("side-nav")) return;
let last = ev;
const mv = (m) => { last = m; if (Math.hypot(m.clientX - ev.clientX, m.clientY - ev.clientY) > 6) stop(); };
const stop = () => {
clearTimeout(timer);
document.removeEventListener("pointermove", mv);
document.removeEventListener("pointerup", stop);
document.removeEventListener("pointercancel", stop);
};
const timer = setTimeout(() => {
stop();
const nav = $("#nav");
const rows = [...nav.querySelectorAll("button[data-plugin-page]")].filter((x) => !pages.get(x.dataset.view)?.entry.replaces);
b.dataset.dragged = "1";
const at = { button: 0, isPrimary: true, pointerId: ev.pointerId, clientX: last.clientX, clientY: last.clientY };
if (!dragRows(at, b, b, nav, rows, (to) => {
const rest = rows.filter((x) => x !== b);
rest.splice(to, 0, b);
rows[to][to > rows.indexOf(b) ? "after" : "before"](b);
api("plugin-pages/arrange", { order: rest.map((x) => x.dataset.view) }).catch((err) => { statusErr(err); load(); });
})) delete b.dataset.dragged;
}, 400);
document.addEventListener("pointermove", mv);
document.addEventListener("pointerup", stop);
document.addEventListener("pointercancel", stop);
}
async function load() {
loadPanels();
let list;
+41
View File
@@ -0,0 +1,41 @@
package gui
import (
"net/http"
"net/http/httptest"
"path/filepath"
"slices"
"strings"
"testing"
"github.com/yetone/magpie/internal/settings"
)
// The sidebar's plugin pages are listed in the order they were dragged to
// (0lVeer on X), and a save of the Settings page leaves that order be.
func TestPluginPagesArrangeKept(t *testing.T) {
h := t.TempDir()
t.Setenv("HOME", h)
t.Setenv("USERPROFILE", h)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
t.Setenv("APPDATA", filepath.Join(h, "AppData", "Roaming"))
t.Setenv("LOCALAPPDATA", filepath.Join(h, "AppData", "Local"))
post := func(path, body string) {
t.Helper()
rec := httptest.NewRecorder()
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
if rec.Code != http.StatusOK {
t.Fatalf("%s: %d %s", path, rec.Code, rec.Body)
}
}
post("/api/plugin-pages/arrange", `{"order":["plugin-b"," plugin-b","plugin-a"]}`)
want := []string{"plugin-b", "plugin-a"}
if got := settings.Load().PluginPageOrder; !slices.Equal(got, want) {
t.Fatalf("order %v, want %v", got, want)
}
post("/api/settings", `{"theme":"dark"}`)
if got := settings.Load().PluginPageOrder; !slices.Equal(got, want) {
t.Fatalf("a Settings save left %v, want %v", got, want)
}
}
+34
View File
@@ -24,6 +24,7 @@ import (
"github.com/yetone/magpie/internal/plugin"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
"github.com/yetone/magpie/internal/usage"
)
@@ -473,6 +474,21 @@ func pluginPageRoutes(mux *http.ServeMux, web bool) {
if out == nil {
out = []pluginPage{}
}
rank := map[string]int{}
for i, k := range settings.Load().PluginPageOrder {
rank[k] = i + 1
}
// the sidebar order the reader dragged; a page it doesn't name follows
slices.SortStableFunc(out, func(a, b pluginPage) int {
ra, rb := rank[a.Key], rank[b.Key]
if ra == 0 {
ra = len(rank) + 1
}
if rb == 0 {
rb = len(rank) + 1
}
return ra - rb
})
for i := range out {
if web && out[i].servicePort() > 0 {
out[i].Service = strings.Repeat("../", strings.Count(out[i].file, "/")) + pageServicePath
@@ -480,6 +496,24 @@ func pluginPageRoutes(mux *http.ServeMux, web bool) {
}
writeJSON(rw, out)
})
mux.HandleFunc("POST /api/plugin-pages/arrange", func(rw http.ResponseWriter, r *http.Request) {
var in struct{ Order []string }
if err := json.NewDecoder(http.MaxBytesReader(rw, r.Body, 64<<10)).Decode(&in); err != nil {
fail(rw, err)
return
}
s, err := settings.LoadChecked()
if err != nil {
fail(rw, err)
return
}
s.PluginPageOrder = in.Order
if err := settings.Save(s); err != nil {
fail(rw, err)
return
}
writeJSON(rw, settingsState())
})
mux.HandleFunc("GET /api/plugin-panels", func(rw http.ResponseWriter, r *http.Request) {
_, out := windowParts()
if out == nil {
+1
View File
@@ -157,6 +157,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) {
GatewayConversations: true,
QuotaLeft: true,
UsageOrder: []string{"kimi", "codex"},
PluginPageOrder: []string{"plugin-b", "plugin-a"},
PanelUsageHidden: []string{"deepseek"},
UsageAgentsHidden: []string{"curl"},
UsageCardsHidden: []string{"stepfun|balance"},
@@ -0,0 +1,76 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The sidebar's plugin pages (0lVeer on X): a press held on a tab picks it
// up, it is dragged to its place and the order is kept (plugin-pages/arrange);
// a quick drag or click moves nothing. The API is faked.
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 entry = (name) => ({ spec: "/x/" + name, name, key: "plugin-" + name, title: name, reads: [], url: `/_magpie/plugin/${"a".repeat(32)}/${name}.html` });
const names = ["alpha", "beta", "gamma"];
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: a held press on a plugin tab drags it and the order is kept`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const context = await browser.newContext({ viewport: { width: 1100, height: 700 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(8000);
const posts = [];
let order = [];
await page.route("**/*", 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:"en",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: "en", theme: "light" } });
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
if (url.pathname === "/api/plugin-pages/arrange") { const b = route.request().postDataJSON(); posts.push(b.order); order = b.order; return json({}); }
if (url.pathname === "/api/plugin-pages") return json(names.map(entry).sort((a, b) => (order.indexOf(a.key) + 1 || 9) - (order.indexOf(b.key) + 1 || 9)));
if (url.pathname === "/api/plugin-panels") return json([]);
if (url.pathname.startsWith("/api/") || url.pathname.startsWith("/_magpie/")) return json({});
if (url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
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: "" }); }
});
await page.goto("http://magpie.test/");
const tabs = page.locator("#nav button[data-plugin-page]");
await tabs.nth(2).waitFor({ state: "attached" });
const keys = () => tabs.evaluateAll((l) => l.map((b) => b.dataset.view.replace("plugin-", "")));
const center = async (i) => { const r = await tabs.nth(i).boundingBox(); return [r.x + r.width / 2, r.y + r.height / 2]; };
assert.deepEqual(await keys(), names);
// quickly dragged: nothing is picked up
let [x, y] = await center(0), [, y2] = await center(2);
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x, y2, { steps: 6 });
await page.mouse.up();
assert.deepEqual(await keys(), names);
assert.deepEqual(posts, []);
// held, then dragged below the last
[x, y] = await center(0);
await page.mouse.move(x, y);
await page.mouse.down();
await page.waitForTimeout(550);
[, y2] = await center(2);
await page.mouse.move(x, y + 8, { steps: 3 });
await page.mouse.move(x, y2 + 6, { steps: 10 });
await page.mouse.up();
await page.waitForFunction(() => !document.querySelector("#nav.sorting"));
assert.deepEqual(await keys(), ["beta", "gamma", "alpha"]);
assert.deepEqual(posts, [["plugin-beta", "plugin-gamma", "plugin-alpha"]]);
assert.equal(await page.evaluate(() => document.querySelector("#view-plugin-alpha")?.classList.contains("on") ?? false), false, "the drop is not a click");
// a reload lists them as kept
await page.reload();
await tabs.nth(2).waitFor({ state: "attached" });
assert.deepEqual(await keys(), ["beta", "gamma", "alpha"]);
});
}
+4
View File
@@ -933,6 +933,9 @@ type Settings struct {
// own order. Only the page's: the order providers are tried in is the
// Providers page's.
UsageOrder []string `json:"usageOrder,omitempty"`
// PluginPageOrder is how the sidebar lists the plugins' pages, by page
// key, as they were dragged there; a page it doesn't name follows.
PluginPageOrder []string `json:"pluginPageOrder,omitempty"`
// PanelUsageHidden are the subscriptions, by provider id, that the tray
// panel's Allowances tab leaves out (H20 on Discord). It is what the
// panel shows, nothing more: routing, caps, the Usage page and the menu
@@ -2542,6 +2545,7 @@ func saveOwn(s Settings, recording, reads bool) error {
s.AgentOrder, s.AgentsHidden, s.AgentsShown = ids(s.AgentOrder), ids(s.AgentsHidden), ids(s.AgentsShown)
s.AgentsHere = ids(s.AgentsHere)
s.UsageOrder = ids(s.UsageOrder)
s.PluginPageOrder = ids(s.PluginPageOrder)
s.PanelUsageHidden = ids(s.PanelUsageHidden)
s.UsageAgentsHidden = ids(s.UsageAgentsHidden)
s.UsageCardsHidden = ids(s.UsageCardsHidden)
+5 -4
View File
@@ -319,10 +319,11 @@ func Merge(body []byte, cur settings.Settings, web bool) (settings.Settings, err
in.RequestArchiveLocal, in.RequestArchiveLocalMB = cur.RequestArchiveLocal, cur.RequestArchiveLocalMB
// used or left is the Usage page's toggle as much as Settings', set on its own
in.QuotaLeft = cur.QuotaLeft
in.QuotaReads = cur.QuotaReads // set on its own (quota-reads)
in.SearchAll = cur.SearchAll // set on its own (search-all)
in.SearchCount = cur.SearchCount // and so is this (search-count)
in.UsageOrder = cur.UsageOrder // the Usage page's, dragged there
in.QuotaReads = cur.QuotaReads // set on its own (quota-reads)
in.SearchAll = cur.SearchAll // set on its own (search-all)
in.SearchCount = cur.SearchCount // and so is this (search-count)
in.UsageOrder = cur.UsageOrder // the Usage page's, dragged there
in.PluginPageOrder = cur.PluginPageOrder // the sidebar plugin pages, dragged there
// and what the tray panel's Allowances tab leaves out, set there
in.PanelUsageHidden = cur.PanelUsageHidden
// and the clients the Usage page's Agents list leaves out, set there