diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-21 10:39:57 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-10-21 10:39:57 +0200 |
| commit | 10ba628793bac9aa26b3ca5a9484b09d1b46e8b6 (patch) | |
| tree | 0642fc66956f3e87c3e3a35a819a0be63bc2e250 /desktop/modules/sbbuilder/Store.qml | |
| parent | e3cbb769f63813a2a2e90aa9607dcc7359a18903 (diff) | |
| download | quickshell-10ba628793bac9aa26b3ca5a9484b09d1b46e8b6.tar.gz quickshell-10ba628793bac9aa26b3ca5a9484b09d1b46e8b6.zip | |
sbbuilder: list the default manifests, and keep them on the first edit
The helper replaces its default [manifests] table with the file's, so
adding one manifest to a file without the table dropped neovim's, and
the page showed no rows for the default that was in effect. With no
table in the file the page now lists the helper's defaults, and the
first add, remove or URL edit writes them all before its own change.
Toml.js gains sections(), to tell a missing table from an empty one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/sbbuilder/Store.qml')
| -rw-r--r-- | desktop/modules/sbbuilder/Store.qml | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/desktop/modules/sbbuilder/Store.qml b/desktop/modules/sbbuilder/Store.qml index c2afa5d..7036f36 100644 --- a/desktop/modules/sbbuilder/Store.qml +++ b/desktop/modules/sbbuilder/Store.qml @@ -32,20 +32,35 @@ QtObject { // Assigned only when the set changes, as Qtm does: a Repeater bound to a // fresh array per keystroke rebuilds the row being typed in. property var manifests: [] + // The helper takes a [manifests] table whole, in place of its default + // one, so with none in the file the default rows are the ones in effect + // and are listed; the first edit writes them all before its own. + readonly property bool manifestsDefault: !T.sections(st.draft).includes("manifests") onDraftChanged: { - const k = T.entries(st.draft, "manifests").map(e => e.key); + const k = st.manifestsDefault ? Object.keys(st.fallback("manifests") ?? {}) + : T.entries(st.draft, "manifests").map(e => e.key); if (JSON.stringify(k) !== JSON.stringify(st.manifests)) st.manifests = k; } + function seedManifests(section) { + if (section !== "manifests" || !st.manifestsDefault) return; + const d = st.fallback("manifests") ?? {}; + for (const k in d) st.draft = T.set(st.draft, "manifests", k, d[k]); + } - function fallback(section, key) { return (st.defaults[section] || {})[key]; } + function fallback(section, key) { return key === undefined ? st.defaults[section] : (st.defaults[section] || {})[key]; } function show(v) { return v === undefined ? undefined : Array.isArray(v) ? v.join(" ") : String(v); } function placeholder(section, key) { return st.show(st.fallback(section, key)) ?? ""; } - function get(section, key) { return st.show(T.get(st.draft, section, key)); } + function get(section, key) { + const v = T.get(st.draft, section, key); + // A listed default manifest shows its URL, so editing starts from it. + return st.show(v === undefined && section === "manifests" && st.manifestsDefault ? st.fallback(section, key) : v); + } // The effective value, typed: the file's, else the default. function value(section, key) { return T.get(st.draft, section, key) ?? st.fallback(section, key); } function entries(section) { return T.entries(st.draft, section); } function put(section, key, v) { + st.seedManifests(section); try { st.draft = T.set(st.draft, section, key, v); } catch (e) { st.error = e.message; st.markInvalid(section + "/" + key, true); // hold Save back @@ -63,7 +78,10 @@ QtObject { : typeof d === "number" ? Number(t) : typeof d === "boolean" ? t === "true" : t); } - function remove(section, key) { st.draft = T.remove(st.draft, section, key); } + function remove(section, key) { + st.seedManifests(section); + st.draft = T.remove(st.draft, section, key); + } function markInvalid(id, bad) { if (!!st.invalid[id] === bad) return; |
