M1.9b: settings dialog with search
settings.open (Mod+,) opens a dialog built from settings.list: sections, controls by type (select, number with min/max, switch), catalog labels and descriptions, search over label, description, key and section, Reset to default, inline errors, live updates on settingsChanged. The theme picker switches at once; editor.fontSize drives --lt-font-size-editor through a token override that survives theme switches. Focus trap, Escape closes. Finishes M1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
db34e2ca52
commit
523d7f684f
17 changed files with 1751 additions and 36 deletions
|
|
@ -47,9 +47,45 @@ export function toResolvedTheme(value: unknown): ResolvedTheme | null {
|
|||
return { id, dark, tokens: clean };
|
||||
}
|
||||
|
||||
/** Token values that settings put above the theme's (`--lt-font-size-editor`). */
|
||||
const overrides = new Map<string, string>();
|
||||
|
||||
/** The last theme's value of every token, to restore when an override ends. */
|
||||
const themeTokens = new Map<string, string>();
|
||||
|
||||
/**
|
||||
* Puts a value above a theme token, now and for every theme applied later,
|
||||
* so a setting such as `editor.fontSize` survives a theme switch. `null`
|
||||
* ends the override and restores the theme's value, or the injected
|
||||
* style's when no theme was applied yet.
|
||||
*
|
||||
* @param name - the token, `--lt-…`.
|
||||
* @param value - the CSS value, or null.
|
||||
* @param root - the element to theme; the document element by default.
|
||||
*/
|
||||
export function setTokenOverride(
|
||||
name: string,
|
||||
value: string | null,
|
||||
root: HTMLElement = document.documentElement,
|
||||
): void {
|
||||
if (value === null) {
|
||||
overrides.delete(name);
|
||||
const base = themeTokens.get(name);
|
||||
if (base === undefined) {
|
||||
root.style.removeProperty(name);
|
||||
} else {
|
||||
root.style.setProperty(name, base);
|
||||
}
|
||||
return;
|
||||
}
|
||||
overrides.set(name, value);
|
||||
root.style.setProperty(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a theme: writes its tokens onto the root element's inline style
|
||||
* (which wins over the injected `<style id="lt-theme">`), sets
|
||||
* (which wins over the injected `<style id="lt-theme">`), keeping the
|
||||
* values of {@link setTokenOverride}, sets
|
||||
* `color-scheme` and records the id in `data-theme`.
|
||||
*
|
||||
* @param theme - the theme.
|
||||
|
|
@ -57,7 +93,8 @@ export function toResolvedTheme(value: unknown): ResolvedTheme | null {
|
|||
*/
|
||||
export function applyTheme(theme: ResolvedTheme, root: HTMLElement = document.documentElement): void {
|
||||
for (const [name, value] of Object.entries(theme.tokens)) {
|
||||
root.style.setProperty(name, value);
|
||||
themeTokens.set(name, value);
|
||||
root.style.setProperty(name, overrides.get(name) ?? value);
|
||||
}
|
||||
root.style.colorScheme = theme.dark ? "dark" : "light";
|
||||
root.dataset.theme = theme.id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue