fix: preset overrides on sidebar

This commit is contained in:
Ian Chua
2026-07-14 12:57:06 +08:00
parent 796080ff76
commit 86a4cec753
10 changed files with 181 additions and 71 deletions

View File

@@ -41,12 +41,8 @@
<div id="configFooter" class="config-view-footer" hidden>
<span id="configValidation" class="config-validation" role="status" aria-live="polite"></span>
<div class="config-actions">
<button id="configUseGlobalBtn" class="ButtonStyleRegular ButtonTypeChoice" type="button"
title="Remove the preset override and use the global configuration again">
Use global
</button>
<button id="configRestoreBtn" class="ButtonStyleRegular ButtonTypeChoice" type="button"
title="Write the plugin defaults into this preset override">
title="Discard this preset's override and use the global configuration again">
Restore defaults
</button>
<button id="configSaveBtn" class="ButtonStyleConfirm ButtonTypeChoice" type="button">Save</button>

View File

@@ -233,21 +233,19 @@ function UpdateConfigMeta(payload) {
const meta = document.getElementById("configMeta");
const badge = document.getElementById("configSourceBadge");
const useGlobal = document.getElementById("configUseGlobalBtn");
const save = document.getElementById("configSaveBtn");
const restore = document.getElementById("configRestoreBtn");
if (!meta || !badge || !useGlobal)
if (!meta || !badge)
return;
const source = String(payload?.source || "none");
badge.textContent = source === "preset" ? "Preset override" :
(source === "base" ? "Inherited from global configuration" : "No saved configuration");
useGlobal.hidden = !selectedHasPresetOverride;
useGlobal.disabled = selectedReadOnly;
if (save)
save.disabled = selectedReadOnly;
// There is nothing to discard when the preset holds no override of its own.
if (restore)
restore.disabled = selectedReadOnly;
restore.disabled = selectedReadOnly || !selectedHasPresetOverride;
meta.hidden = false;
}
@@ -361,22 +359,11 @@ function SaveCapabilityConfig() {
});
}
// Asks the native side to write the capability's default config over whatever is stored. The
// defaults come from the capability's get_default_config(), never from this page — the host does not
// know what a given plugin considers default. The native side confirms before discarding anything,
// and replies with the same "saved" payload, so both editors reload from what was persisted.
// Drops the preset's override, which is what "default" means here: the capability falls back to the
// global configuration, the same as a preset that was never overridden. The native side confirms
// before discarding it and then re-sends the capability's config, so the editors reload from what is
// now effective rather than from what was typed.
function RestoreCapabilityConfig() {
if (!selectedPluginKey || !selectedCapabilityName)
return;
SendMessage("restore_preset_defaults", {
plugin_key: selectedPluginKey,
capability_name: selectedCapabilityName,
capability_type: selectedCapabilityType
});
}
function UseGlobalCapabilityConfig() {
if (!selectedPluginKey || !selectedCapabilityName || !selectedHasPresetOverride)
return;
@@ -482,10 +469,6 @@ document.addEventListener("DOMContentLoaded", () => {
if (restoreBtn)
restoreBtn.addEventListener("click", RestoreCapabilityConfig);
const useGlobalBtn = document.getElementById("configUseGlobalBtn");
if (useGlobalBtn)
useGlobalBtn.addEventListener("click", UseGlobalCapabilityConfig);
const text = document.getElementById("configText");
if (text)
text.addEventListener("input", ValidateConfigText);