Files
magpie/internal/gui/assets/setfeats.js
T
yetone 975799a069 gui: Settings' search finds what the words are about (canlee886 on X)
canlee886 (X, 2123329450502938656) searched Settings for "可访问性",
"监控" and "自动选择模型" and each said no setting matched: "缺少搜索时
的智能联想". The search only found settings whose text had every word.

What it does now, all in finder.js, in the page, nothing sent anywhere:
- A table of ~30 concepts, each with the words a reader may type in
  en, zh, zh-TW, ja and de (accessibility, monitoring, picking a model
  by itself, theme, proxy, notifications, startup, privacy, LAN, cost,
  quota, hotkey, ...), leading to the English names of the settings it
  covers (a setting's English is its data-en in every language). Those
  settings are listed with the ones that have the words themselves,
  for rows, built-ins and other pages' places alike.
- When nothing has the words: a long run of Chinese or Japanese is read
  by its two-character words ("文字大小调整" finds Text size), and a
  Latin word over 3 letters may be one edit off ("currancy").
- When no setting has the words themselves but some are related, the
  line over the parts says "Settings related to “…”" (start-aligned,
  in every language) instead of "No setting matches".
- The finders count first (setFeatsFind/elseFind take a dry flag), so
  a search renders once and the view's MutationObserver doesn't loop.

Not done, on purpose: pinyin (a large table, and readers type Chinese
through an IME), a recent-searches list and "did you mean" chips (a
layout that jumps on focus; the owner has said no to UI churn).

Run (WSL magpie-desktop: mote's load was 26 to 34 on 18 cores, mica's
disk is full):
- settings-search-related.test.cjs (new), Chromium and WebKit, en, zh,
  zh-TW, ja, de at 560x420, plus magpie web at 390x760: 16 of 16.
  Against origin/main 9bf5848c1's assets (SEARCH_ASSETS): 0 of 16, "無
  障礙"/"accessibility"/"barrierefreiheit" show no Text size.
- 37 nearby GUI files (settings-*, search-*, find-*, i18n*, menu-scroll,
  click-scroll, builtins): 636 pass, 34 fail. The six files with reds,
  run again at origin/main 9bf5848c1 and at the change: builtins,
  click-scroll, menu-scroll and settings-update-source are red the same
  at both (#4120, #4471, #1550); search-key-list/search-keys time out
  on one subtest a run, a different one each time, at the change only,
  and touch no Settings search: filed as #7194.
- At the rebased head (239da9991): settings-search-related,
  settings-search, settings-search-reach, find-anywhere and i18n-keys,
  64 of 64; go test ./internal/gui (TestCoreScriptBudget and the rest)
  on Windows (xiaomi-gpu), since WSL has no gtk4: TestCoreScriptBudget and
  the i18n checks pass; 10 Windows reds, none in assets, all filed
  (#6068: TestLodyImportHandoff's %AppData%, TestUpdateThatWontStart,
  TestGatewayHeldByAContainer, ...; #7112 TestSetPortServes...).
- Broken by hand: the base-assets run above.

Not tried: the whole GUI suite (WSL and mote were busy with other
sessions' suites; mica has no disk), the real app (only Playwright's
engines, not WebKitGTK or WKWebView; no motion was added).
2026-11-19 17:21:45 +08:00

71 lines
3.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Settings' search, through Plugins › Built-in too: a built-in's switch,
// and the settings it has there or on its own page (Gateway's Recent calls
// at a time), were found by nothing in Settings, and one switched off took
// its Settings rows away with it, so a search for it said no setting
// matched (the scattered settings audit after netube99 on X). Each built-in
// whose name, words or settings match is listed after Settings' own rows,
// off ones too, and Open goes to its row in Plugins › Built-in. Loaded by
// app.js the first time a search runs, as provlinks.js is.
// the built-in an Open is for: its row is lit (and scrolled to once) each
// time Plugins › Built-in draws it in the next few seconds, as the list is
// drawn again when the plugins are read
let featAt = null, featAtEnd = 0;
{
const draw = window.renderBuiltins;
window.renderBuiltins = (box, list, done) => {
draw(box, list, done);
const row = featAt && box.querySelector(`.feat-row[data-id="${featAt.id}"]`);
if (!row) return;
if (!featAt.scrolled) row.scrollIntoView({ block: "center" });
featAt.scrolled = true;
row.classList.add("flash");
};
}
// fq is finder.js's findQuery; dry counts them and draws nothing
window.setFeatsFind = function (fq, dry) {
const say = (s) => (s ? s + " " + t(s) : "");
const found = ((fq?.key && prefs?.builtins) || []).filter((f) => {
const props = Object.values(f.schema?.properties || {});
const text = [say(f.name), say(f.sub), ...props.map((p) => say(p.title) + " " + say(p.description))].join(" ").toLowerCase();
return fq.test(text, [say(f.name), ...props.map((p) => say(p.title))].join(" ").toLowerCase());
});
if (dry) return found.length;
let box = document.getElementById("setFeats");
if (!box) {
box = el("section", "set-page set-feats");
box.id = "setFeats";
box.append(el("div", "list prefs"));
$("#view-settings").append(box);
}
const list = box.firstChild;
// drawn again only when it changes: a draw is a change Settings'
// observer runs the search again on
const key = document.documentElement.lang + " " + found.map((f) => f.id + (f.on ? "+" : "-")).join(" ");
if (box.dataset.key === key) return found.length;
box.dataset.key = key;
list.replaceChildren();
for (const f of found) {
const r = el("div", "row pref feat-find");
r.dataset.id = f.id;
const who = el("div", "who");
who.append(el("div", "name", t(f.name)));
const sub = [f.on ? "" : t("Off"), f.sub ? t(f.sub) : ""].filter(Boolean).join(" · ");
if (sub) who.append(el("div", "sub", sub));
const go = el("button", "text", t("Open"));
go.type = "button";
go.onclick = () => {
featAt = { id: f.id, scrolled: false };
clearTimeout(featAtEnd);
featAtEnd = setTimeout(() => { featAt = null; }, 3000);
window.pluginTabTo?.("builtin");
show("plugins");
};
r.append(who, go);
list.append(r);
}
box.dataset.part = t("Plugins") + " › " + t("Built-in");
box.hidden = !found.length;
return found.length;
};