chore: cleanup comments

This commit is contained in:
2026-06-30 22:27:37 +02:00
parent 2b89c8e4a1
commit 865b5bda53
5 changed files with 11 additions and 164 deletions
+1 -47
View File
@@ -6,37 +6,13 @@ import Quickshell
import ZShell
import qs.Config
// Search service over the settings index. The index is generated at build time
// from the page QML files by scripts/build-settings-index.py and baked into the
// plugin binary (read via CUtils.settingsIndex), so it stays in sync with the UI
// without any hand-maintained entries and without a user-editable data file.
//
// Unlike the launcher's fuzzy searcher, this uses the real inverted index +
// ranking baked into the JSON: a query is tokenised, each token is looked up in
// the inverted index (exact token or prefix), the matching entry ids are scored
// with the precomputed per-token ranking, and the best entries are returned.
// SettingEntry QObjects are produced via Variants so the result objects expose
// the same properties the result list expects.
Singleton {
id: root
// fzf finder over the entries (title + keywords), used as a fuzzy fallback
// when the exact/prefix index lookup comes up short. fzf is the same matcher
// the launcher uses, so typo and mid-word matching behave consistently.
property var fzfFinder: null
// entries: forward index (one record per setting)
// inverted: token -> [entry id...]
// ranking: token -> { entry id (string): weight }
property var inverted: ({})
property var ranking: ({})
// Wrap the parts of `text` that match the search in the given colour, for use
// with a StyledText in Text.StyledText format. Matches each query token as a
// prefix at a word boundary (mirroring how lookup matches), so "wall"
// highlights the start of "wallpaper". StyledText supports <font color> but
// not CSS <span style>. HTML-significant characters are escaped first so the
// rich-text parser doesn't choke on names with & < or >.
function highlight(text: string, search: string, colour: color): string {
const escaped = text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
const tokens = tokenize(search);
@@ -47,9 +23,6 @@ Singleton {
return escaped.replace(pattern, `<font color="${colour}">$1</font>`);
}
// Look up a query token in the inverted index: exact match first, then any
// indexed token that starts with it (prefix search, so "wif" finds "wifi").
// Returns a map of entry id -> best ranking weight for that id.
function lookup(token: string): var {
const result = ({});
const exact = root.inverted[token] !== undefined;
@@ -71,31 +44,21 @@ Singleton {
if (tokens.length === 0)
return [];
// Accumulate a score per entry id across all query tokens. An entry must
// match every query token (AND), and its score is the sum of the ranking
// weights of the index tokens it matched, so results stay relevant.
const scores = ({});
const hitCounts = ({});
for (const token of tokens) {
const matches = root.lookup(token); // { id: weight }
const matches = root.lookup(token);
for (const id in matches) {
scores[id] = (scores[id] ?? 0) + matches[id];
hitCounts[id] = (hitCounts[id] ?? 0) + 1;
}
}
// Sort by score, breaking ties by id so the order is stable (otherwise
// entries with equal scores can be dropped arbitrarily by the limit).
const ranked = Object.keys(scores).filter(id => hitCounts[id] === tokens.length).sort((a, b) => scores[b] - scores[a] || (parseInt(a) - parseInt(b))).slice(0, 25);
const all = entries.instances;
const out = ranked.map(id => all[parseInt(id)]).filter(e => e !== undefined);
// The inverted index only does exact/prefix matches. When it finds little
// or nothing - a typo ("trasparency") or a mid-word query ("paper") - fall
// back to fzf over the same entries. fzf hits that the index already
// returned are skipped, and the rest are appended after the (stronger)
// index results, so precise matches always lead.
if (out.length < 5 && root.fzfFinder) {
const seen = ({});
for (const id of ranked)
@@ -127,9 +90,6 @@ Singleton {
entries.model = data.entries;
root.inverted = data.inverted ?? {};
root.ranking = data.ranking ?? {};
// One searchable string per entry: the title. fzf provides typo and
// mid-word matching over titles as a fallback when the exact/prefix
// index lookup comes up short.
const docs = data.entries.map((e, i) => ({
idx: i,
text: e.title
@@ -164,12 +124,7 @@ Singleton {
readonly property var subPath: modelData.subPath
readonly property string subtext: modelData.subtext ?? ""
readonly property string title: modelData.title
// A non-empty togglePath means this is a plain on/off setting that can be
// flipped straight from the results (e.g. "background.wallpaperEnabled").
readonly property string togglePath: modelData.togglePath ?? ""
// Live value of the config property, read by walking the path on
// GlobalConfig. Re-evaluates when that property changes.
readonly property bool toggleValue: {
if (!isToggle)
return false;
@@ -183,7 +138,6 @@ Singleton {
return obj ?? false;
}
// Write `value` back to the config property the path points at.
function setToggle(value: bool): void {
if (!isToggle)
return;