T1: four more themes, theme picker, theme file import, editor font settings
Plum Night, River, Paper and Reed (designed by Amy, approved by Daniel) join the brand pair. theme.list/current/select/import, a picker with live preview (view.selectTheme) and "Import Theme…" (view.importTheme); imported themes are validated and stored in <data_dir>/themes. Editor font family and line height settings apply live. Docs: docs/themes.md. Gate: fmt, clippy and the rest pass up to cargo test, where only the unrelated lutra-terminal PTY test a_full_buffer_stops_the_shell timed out under load; to be re-run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
872b5cb258
commit
086bc8a925
26 changed files with 2881 additions and 100 deletions
|
|
@ -3,7 +3,8 @@
|
|||
* Root component: mounts the main window layout with the editor area; the
|
||||
* slogan shows while no tab is open, and the restore dialog for unsaved
|
||||
* texts from the recovery journal, the toast stack, the command palette,
|
||||
* the go-to popup, the settings dialog and the merge dialog. Loads product information from the engine on
|
||||
* the go-to popup, the settings dialog, the merge dialog and the theme
|
||||
* picker. Loads product information from the engine on
|
||||
* mount, starts showing notifications, following the theme (see
|
||||
* `theme.ts`; a failed theme report raises an error toast) and the global
|
||||
* keymap with the UI commands (see `commands/store.ts`), and loads the settings so the
|
||||
|
|
@ -22,6 +23,7 @@ import NotificationStack from "./components/notifications/NotificationStack.vue"
|
|||
import RecoveryDialog from "./components/recovery/RecoveryDialog.vue";
|
||||
import SettingsDialog from "./components/settings/SettingsDialog.vue";
|
||||
import MergeDialog from "./components/vcs/merge/MergeDialog.vue";
|
||||
import ThemePicker from "./components/theme/ThemePicker.vue";
|
||||
import { useAppStore } from "./stores/app";
|
||||
import { useAutosaveStore } from "./stores/autosave";
|
||||
import { useNotificationsStore } from "./stores/notifications";
|
||||
|
|
@ -73,6 +75,7 @@ onUnmounted(() => {
|
|||
<GotoPopup />
|
||||
<SettingsDialog />
|
||||
<MergeDialog />
|
||||
<ThemePicker />
|
||||
<NavLayer />
|
||||
<NotificationStack />
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@
|
|||
* - **Navigation (M3.5):** the definition picker and the inline rename field
|
||||
* are exclusive modals too. So is the branches popup (M4.5), and so are
|
||||
* "Clone Repository…" and "Manage Remotes…" (M4.10), the merge
|
||||
* dialog (M4.8) and the stash dialog (M4.9), and the deployment servers
|
||||
* dialog (G17).
|
||||
* dialog (M4.8) and the stash dialog (M4.9), the deployment servers
|
||||
* dialog (G17) and the theme picker (C9 T1).
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, watch } from "vue";
|
||||
|
|
@ -41,7 +41,8 @@ export type ModalId =
|
|||
| "remotes"
|
||||
| "deployment"
|
||||
| "merge"
|
||||
| "stash";
|
||||
| "stash"
|
||||
| "themes";
|
||||
|
||||
/** Store of the open exclusive modal. */
|
||||
export const useModalsStore = defineStore("modals", () => {
|
||||
|
|
|
|||
|
|
@ -66,4 +66,6 @@ export const UI_COMMANDS: readonly UiCommandSpec[] = [
|
|||
{ id: "vcs.nextChange", labelKey: "command.vcs.nextChange", menuPath: "Git/Next Change", defaultShortcut: "Alt+Shift+]" },
|
||||
{ id: "vcs.previousChange", labelKey: "command.vcs.previousChange", menuPath: "Git/Previous Change", defaultShortcut: "Alt+Shift+[" },
|
||||
{ id: "view.toggleStructure", labelKey: "command.view.toggleStructure", menuPath: "View/Structure", defaultShortcut: "Mod+2" },
|
||||
{ id: "view.selectTheme", labelKey: "command.view.selectTheme", menuPath: "View/Select Theme…" },
|
||||
{ id: "view.importTheme", labelKey: "command.view.importTheme", menuPath: "View/Import Theme…" },
|
||||
];
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export const lutraEditorTheme: Extension = EditorView.theme({
|
|||
},
|
||||
".cm-scroller": {
|
||||
fontFamily: "var(--lt-font-mono)",
|
||||
lineHeight: "1.5",
|
||||
lineHeight: "var(--lt-line-height-editor)",
|
||||
},
|
||||
".cm-content": {
|
||||
caretColor: "var(--lt-editor-cursor)",
|
||||
|
|
|
|||
285
ui/src/components/theme/ThemePicker.vue
Normal file
285
ui/src/components/theme/ThemePicker.vue
Normal file
|
|
@ -0,0 +1,285 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The theme picker (C9 T1): "Select Theme…" lists the built-in and imported
|
||||
* themes with a swatch of each (window, editor, accent, keyword and string
|
||||
* colour) and "Same as system". Up/Down, Home and End move the selection
|
||||
* and preview the theme live; Enter or a click switches to it; Escape or a
|
||||
* click outside puts the previous theme back. Also supplies "Import
|
||||
* Theme…". An exclusive modal (`commands/modals.ts`).
|
||||
*/
|
||||
import { Monitor } from "@lucide/vue";
|
||||
import { nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { useModalsStore } from "../../commands/modals";
|
||||
import { useCommandsStore } from "../../commands/store";
|
||||
import { t } from "../../i18n";
|
||||
import { useThemesStore, type ThemeInfo } from "./themes";
|
||||
|
||||
const themes = useThemesStore();
|
||||
const modals = useModalsStore();
|
||||
const commands = useCommandsStore();
|
||||
|
||||
/** The list element, which holds the focus. */
|
||||
const list = ref<HTMLElement | null>(null);
|
||||
|
||||
/** Element that had the focus before the picker opened. */
|
||||
let returnFocus: HTMLElement | null = null;
|
||||
|
||||
/** Withdraws the UI commands; set while mounted. */
|
||||
let withdraw: (() => void)[] = [];
|
||||
|
||||
/** Swatch tokens, in the order they are drawn. */
|
||||
const SWATCH = ["--lt-bg", "--lt-editor-bg", "--lt-accent", "--lt-syntax-keyword", "--lt-syntax-string"] as const;
|
||||
|
||||
/**
|
||||
* The swatch colours of a theme.
|
||||
*
|
||||
* @param info - the theme.
|
||||
* @returns CSS colours; empty for "Same as system".
|
||||
*/
|
||||
function swatch(info: ThemeInfo): string[] {
|
||||
const tokens = info.theme?.tokens ?? {};
|
||||
return SWATCH.map((name) => tokens[name] ?? "transparent");
|
||||
}
|
||||
|
||||
/**
|
||||
* The second line of a row: dark or light, and whether it was imported.
|
||||
*
|
||||
* @param info - the theme.
|
||||
*/
|
||||
function kindOf(info: ThemeInfo): string {
|
||||
if (info.dark === null) {
|
||||
return t("theme.picker.followsSystem");
|
||||
}
|
||||
const mode = info.dark ? t("theme.picker.dark") : t("theme.picker.light");
|
||||
return info.builtin ? mode : t("theme.picker.imported", { mode });
|
||||
}
|
||||
|
||||
/**
|
||||
* Keyboard handling of the list.
|
||||
*
|
||||
* @param event - the key press.
|
||||
*/
|
||||
function onKeydown(event: KeyboardEvent): void {
|
||||
const count = themes.items.length;
|
||||
const moves: Record<string, number> = { ArrowDown: 1, ArrowUp: -1, Home: -count, End: count };
|
||||
const delta = moves[event.key];
|
||||
if (delta !== undefined) {
|
||||
themes.move(delta);
|
||||
scrollSelected();
|
||||
} else if (event.key === "Enter") {
|
||||
void themes.choose();
|
||||
} else if (event.key === "Escape") {
|
||||
themes.cancel();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
/** Keeps the selected row in view. */
|
||||
function scrollSelected(): void {
|
||||
void nextTick(() => {
|
||||
const row = list.value?.querySelector<HTMLElement>(`#lt-theme-${String(themes.selected)}`);
|
||||
if (row && typeof row.scrollIntoView === "function") {
|
||||
row.scrollIntoView({ block: "nearest" });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
watch(
|
||||
() => themes.open,
|
||||
(open) => {
|
||||
if (open) {
|
||||
const active = document.activeElement;
|
||||
returnFocus = active instanceof HTMLElement ? active : null;
|
||||
modals.opened("themes", () => {
|
||||
themes.cancel();
|
||||
});
|
||||
void nextTick(() => {
|
||||
list.value?.focus();
|
||||
scrollSelected();
|
||||
});
|
||||
} else {
|
||||
modals.closed("themes");
|
||||
returnFocus?.focus();
|
||||
returnFocus = null;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
withdraw = [
|
||||
commands.provide("view.selectTheme", { run: () => themes.show() }),
|
||||
commands.provide("view.importTheme", { run: () => themes.importFile() }),
|
||||
];
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
for (const stop of withdraw) {
|
||||
stop();
|
||||
}
|
||||
withdraw = [];
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="themes.open"
|
||||
class="theme-picker"
|
||||
data-test="theme-picker"
|
||||
@mousedown.self.prevent="themes.cancel()"
|
||||
>
|
||||
<div
|
||||
class="theme-picker__dialog"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
:aria-label="t('theme.picker.title')"
|
||||
>
|
||||
<p class="theme-picker__title">
|
||||
{{ t("theme.picker.title") }}
|
||||
</p>
|
||||
<ul
|
||||
ref="list"
|
||||
class="theme-picker__list"
|
||||
role="listbox"
|
||||
tabindex="0"
|
||||
:aria-label="t('theme.picker.title')"
|
||||
:aria-activedescendant="`lt-theme-${String(themes.selected)}`"
|
||||
data-test="theme-picker-list"
|
||||
@keydown="onKeydown"
|
||||
>
|
||||
<li
|
||||
v-for="(item, index) in themes.items"
|
||||
:id="`lt-theme-${String(index)}`"
|
||||
:key="item.id"
|
||||
class="theme-picker__row"
|
||||
:class="{ 'theme-picker__row--selected': index === themes.selected }"
|
||||
role="option"
|
||||
:aria-selected="index === themes.selected"
|
||||
:data-id="item.id"
|
||||
data-test="theme-picker-row"
|
||||
@mousemove="themes.hover(index)"
|
||||
@mousedown.prevent
|
||||
@click="themes.choose(index)"
|
||||
>
|
||||
<span
|
||||
v-if="item.theme"
|
||||
class="theme-picker__swatch"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<span
|
||||
v-for="(colour, part) in swatch(item)"
|
||||
:key="part"
|
||||
class="theme-picker__chip"
|
||||
:style="{ background: colour }"
|
||||
/>
|
||||
</span>
|
||||
<Monitor
|
||||
v-else
|
||||
class="theme-picker__icon"
|
||||
:size="14"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span class="theme-picker__name">{{ item.name }}</span>
|
||||
<span class="theme-picker__kind">{{ kindOf(item) }}</span>
|
||||
<span
|
||||
v-if="item.id === themes.initialId"
|
||||
class="theme-picker__current"
|
||||
>{{ t("theme.picker.current") }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.theme-picker {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
padding-top: 12vh;
|
||||
background: color-mix(in srgb, var(--lt-bg) 40%, transparent);
|
||||
z-index: 30;
|
||||
}
|
||||
|
||||
.theme-picker__dialog {
|
||||
width: min(480px, 90vw);
|
||||
max-height: 60vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--lt-bg);
|
||||
color: var(--lt-fg);
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: var(--lt-radius, 4px);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.theme-picker__title {
|
||||
margin: 0;
|
||||
padding: var(--lt-space-s, 4px) var(--lt-space-m, 8px);
|
||||
font-weight: 600;
|
||||
border-bottom: 1px solid var(--lt-border);
|
||||
}
|
||||
|
||||
.theme-picker__list {
|
||||
margin: 0;
|
||||
padding: var(--lt-space-s, 4px) 0;
|
||||
list-style: none;
|
||||
overflow-y: auto;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.theme-picker__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--lt-space-m, 8px);
|
||||
padding: 5px var(--lt-space-m, 8px);
|
||||
white-space: nowrap;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.theme-picker__row--selected {
|
||||
background: var(--lt-editor-selection-bg);
|
||||
}
|
||||
|
||||
.theme-picker__swatch {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.theme-picker__chip {
|
||||
width: 10px;
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
.theme-picker__icon {
|
||||
flex-shrink: 0;
|
||||
width: 52px;
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.theme-picker__name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.theme-picker__kind,
|
||||
.theme-picker__current {
|
||||
flex-shrink: 0;
|
||||
color: var(--lt-fg-muted);
|
||||
font-size: var(--lt-font-size-small);
|
||||
}
|
||||
|
||||
.theme-picker__row--selected .theme-picker__kind,
|
||||
.theme-picker__row--selected .theme-picker__current {
|
||||
color: var(--lt-fg);
|
||||
}
|
||||
</style>
|
||||
232
ui/src/components/theme/themes.ts
Normal file
232
ui/src/components/theme/themes.ts
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
/**
|
||||
* The theme picker and theme import (C9 T1).
|
||||
*
|
||||
* - **Picker:** "Select Theme…" (`view.selectTheme`) lists the built-in
|
||||
* and imported themes from `theme.list`, plus "Same as system". Moving
|
||||
* the selection previews the theme live (its tokens go onto `:root`
|
||||
* through `applyTheme`); Enter or a click switches to it with
|
||||
* `theme.select`; Escape puts the theme in use back. An exclusive modal
|
||||
* (`commands/modals.ts`).
|
||||
* - **Import:** "Import Theme…" (`view.importTheme`) asks for a theme file
|
||||
* (format: `docs/themes.md`) and runs `theme.import`, which stores the
|
||||
* theme in Lutra's data directory and switches to it. A broken file
|
||||
* gives an error toast with the engine's reason.
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
import { hasMessage, t } from "../../i18n";
|
||||
import { pickFile, run } from "../../ipc";
|
||||
import { useNotificationsStore } from "../../stores/notifications";
|
||||
import { applyTheme, toResolvedTheme, type ResolvedTheme } from "../../theme";
|
||||
|
||||
/** The `appearance.theme` value that follows the OS. */
|
||||
export const SYSTEM = "system";
|
||||
|
||||
/** Most themes read from `theme.list`. */
|
||||
export const MAX_THEMES = 500;
|
||||
|
||||
/** A theme as the picker lists it. */
|
||||
export interface ThemeInfo {
|
||||
/** Theme id, or {@link SYSTEM}. */
|
||||
id: string;
|
||||
/** Display name: catalog text for built-in themes, the file's name for imported ones. */
|
||||
name: string;
|
||||
/** Whether the theme is dark; null for {@link SYSTEM}. */
|
||||
dark: boolean | null;
|
||||
/** Whether Lutra ships it. */
|
||||
builtin: boolean;
|
||||
/** Its tokens for the preview; null for {@link SYSTEM}. */
|
||||
theme: ResolvedTheme | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads one `theme.list` entry from untrusted data.
|
||||
*
|
||||
* @param raw - the entry.
|
||||
* @returns the theme, or null if it is malformed.
|
||||
*/
|
||||
export function toThemeInfo(raw: unknown): ThemeInfo | null {
|
||||
const theme = toResolvedTheme(raw);
|
||||
if (!theme) {
|
||||
return null;
|
||||
}
|
||||
const { label, name, builtin } = raw as Record<string, unknown>;
|
||||
const shown =
|
||||
typeof label === "string" && hasMessage(label)
|
||||
? t(label)
|
||||
: typeof name === "string" && name.trim() !== ""
|
||||
? name.trim()
|
||||
: theme.id;
|
||||
return { id: theme.id, name: shown, dark: theme.dark, builtin: builtin === true, theme };
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the `theme.list` result and appends "Same as system".
|
||||
*
|
||||
* @param raw - the result.
|
||||
* @returns the themes, or null if the result is not a list.
|
||||
*/
|
||||
export function toThemeList(raw: unknown): ThemeInfo[] | null {
|
||||
if (!Array.isArray(raw)) {
|
||||
return null;
|
||||
}
|
||||
const themes = (raw as unknown[])
|
||||
.slice(0, MAX_THEMES)
|
||||
.map(toThemeInfo)
|
||||
.filter((info): info is ThemeInfo => info !== null);
|
||||
themes.push({
|
||||
id: SYSTEM,
|
||||
name: t("settings.appearance.theme.value.system"),
|
||||
dark: null,
|
||||
builtin: true,
|
||||
theme: null,
|
||||
});
|
||||
return themes;
|
||||
}
|
||||
|
||||
/** Store of the theme picker. */
|
||||
export const useThemesStore = defineStore("themes", () => {
|
||||
const notifications = useNotificationsStore();
|
||||
/** Themes in picker order; empty while closed. */
|
||||
const items = ref<ThemeInfo[]>([]);
|
||||
/** Index of the selected row. */
|
||||
const selected = ref(0);
|
||||
/** Whether the picker is shown. */
|
||||
const open = ref(false);
|
||||
/** Id of the theme setting when the picker opened. */
|
||||
const initialId = ref<string | null>(null);
|
||||
/** The theme on screen when the picker opened, to restore on Escape. */
|
||||
let initialTheme: ResolvedTheme | null = null;
|
||||
|
||||
/** The selected theme, or null. */
|
||||
const current = computed(() => items.value[selected.value] ?? null);
|
||||
|
||||
/**
|
||||
* Shows a theme's tokens without switching to it. "Same as system" shows
|
||||
* the theme in use when the picker opened.
|
||||
*
|
||||
* @param info - the theme.
|
||||
*/
|
||||
function preview(info: ThemeInfo | null): void {
|
||||
const theme = info?.theme ?? initialTheme;
|
||||
if (theme) {
|
||||
applyTheme(theme);
|
||||
}
|
||||
}
|
||||
|
||||
/** Opens the picker with the current theme selected. A failed load raises an error toast. */
|
||||
async function show(): Promise<void> {
|
||||
const [listed, setting, now] = await Promise.all([
|
||||
run("theme.list"),
|
||||
run("settings.get", { keys: ["appearance.theme"] }),
|
||||
run("theme.current"),
|
||||
]);
|
||||
if (!listed.ok) {
|
||||
notifications.notifyError("theme.list", listed.error);
|
||||
return;
|
||||
}
|
||||
const list = toThemeList(listed.value);
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
const values = setting.ok ? (setting.value as { values?: Record<string, unknown> } | null)?.values : undefined;
|
||||
const id = typeof values?.["appearance.theme"] === "string" ? values["appearance.theme"] : null;
|
||||
initialId.value = id;
|
||||
initialTheme = now.ok ? toResolvedTheme(now.value) : null;
|
||||
items.value = list;
|
||||
selected.value = Math.max(0, list.findIndex((info) => info.id === id));
|
||||
open.value = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the selection and previews the theme there.
|
||||
*
|
||||
* @param delta - rows to move; clamped to the list.
|
||||
*/
|
||||
function move(delta: number): void {
|
||||
const count = items.value.length;
|
||||
if (count === 0) {
|
||||
return;
|
||||
}
|
||||
selected.value = Math.min(count - 1, Math.max(0, selected.value + delta));
|
||||
preview(current.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a row by index and previews it.
|
||||
*
|
||||
* @param index - the row.
|
||||
*/
|
||||
function hover(index: number): void {
|
||||
if (index >= 0 && index < items.value.length && index !== selected.value) {
|
||||
selected.value = index;
|
||||
preview(current.value);
|
||||
}
|
||||
}
|
||||
|
||||
/** Closes the picker and puts the theme in use back. */
|
||||
function cancel(): void {
|
||||
if (!open.value) {
|
||||
return;
|
||||
}
|
||||
open.value = false;
|
||||
if (initialTheme) {
|
||||
applyTheme(initialTheme);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches to a theme with `theme.select` and closes the picker. A
|
||||
* failure puts the previous theme back and raises an error toast.
|
||||
*
|
||||
* @param index - the row; the selected one when absent.
|
||||
*/
|
||||
async function choose(index?: number): Promise<void> {
|
||||
const info = items.value[index ?? selected.value];
|
||||
if (!open.value || !info) {
|
||||
return;
|
||||
}
|
||||
open.value = false;
|
||||
const result = await run("theme.select", { id: info.id });
|
||||
if (!result.ok) {
|
||||
if (initialTheme) {
|
||||
applyTheme(initialTheme);
|
||||
}
|
||||
notifications.notifyError("theme.select", result.error);
|
||||
return;
|
||||
}
|
||||
const theme = toResolvedTheme(result.value);
|
||||
if (theme) {
|
||||
applyTheme(theme);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks for a theme file and imports it with `theme.import`. Cancelling
|
||||
* the file dialog does nothing; success shows an info toast with the
|
||||
* theme's name; a broken file shows the engine's reason.
|
||||
*/
|
||||
async function importFile(): Promise<void> {
|
||||
const picked = await pickFile(t("theme.import.title"));
|
||||
if (!picked.ok) {
|
||||
notifications.notifyError("theme.import", picked.error);
|
||||
return;
|
||||
}
|
||||
if (picked.value === null) {
|
||||
return;
|
||||
}
|
||||
const result = await run("theme.import", { path: picked.value });
|
||||
if (!result.ok) {
|
||||
notifications.notifyError("theme.import", result.error);
|
||||
return;
|
||||
}
|
||||
const name = (result.value as { name?: unknown } | null)?.name;
|
||||
notifications.notify({
|
||||
level: "info",
|
||||
messageKey: "theme.import.done",
|
||||
params: { name: typeof name === "string" ? name : picked.value },
|
||||
});
|
||||
}
|
||||
|
||||
return { items, selected, open, initialId, current, show, move, hover, cancel, choose, importFile };
|
||||
});
|
||||
|
|
@ -49,6 +49,8 @@
|
|||
"command.vcs.showStashes": "Stashes…",
|
||||
"command.vcs.stash": "Stash Changes…",
|
||||
"command.vcs.toggleBlame": "Annotate with Git Blame",
|
||||
"command.view.importTheme": "Import Theme…",
|
||||
"command.view.selectTheme": "Select Theme…",
|
||||
"command.view.toggleProjectTree": "Show or Hide Project",
|
||||
"command.view.toggleStructure": "Show or Hide Structure",
|
||||
"common.cancel": "Cancel",
|
||||
|
|
@ -359,6 +361,10 @@
|
|||
"settings.appearance.theme.label": "Theme",
|
||||
"settings.appearance.theme.value.lutraDark": "Lutra Dark",
|
||||
"settings.appearance.theme.value.lutraLight": "Lutra Light",
|
||||
"settings.appearance.theme.value.lutraPaper": "Paper",
|
||||
"settings.appearance.theme.value.lutraPlumNight": "Plum Night",
|
||||
"settings.appearance.theme.value.lutraReed": "Reed",
|
||||
"settings.appearance.theme.value.lutraRiver": "River",
|
||||
"settings.appearance.theme.value.system": "Same as system",
|
||||
"settings.dialog.browse": "Browse…",
|
||||
"settings.dialog.browseLabel": "Choose a file for {name}",
|
||||
|
|
@ -380,10 +386,14 @@
|
|||
"settings.editor.completion.autoPopup.label": "Show completions while typing",
|
||||
"settings.editor.completion.delayMs.description": "How long Lutra waits after you stop typing before it asks for completions. 0 asks at once.",
|
||||
"settings.editor.completion.delayMs.label": "Completion popup delay (ms)",
|
||||
"settings.editor.fontFamily.description": "Font family of the editor, the terminal and other code text, as a CSS list such as \"JetBrains Mono\", monospace. Empty uses Lutra's default monospace fonts.",
|
||||
"settings.editor.fontFamily.label": "Editor font",
|
||||
"settings.editor.fontSize.description": "Size of the text in the editor, in pixels.",
|
||||
"settings.editor.fontSize.label": "Editor font size",
|
||||
"settings.editor.hover.delayMs.description": "How long the pointer has to rest on a name before its documentation shows.",
|
||||
"settings.editor.hover.delayMs.label": "Documentation tooltip delay (ms)",
|
||||
"settings.editor.lineHeight.description": "Height of each editor line relative to the font size. 150 means one and a half times the font size.",
|
||||
"settings.editor.lineHeight.label": "Editor line height (%)",
|
||||
"settings.error.browseFailed": "The file picker could not open: {message}",
|
||||
"settings.error.int": "Enter a whole number",
|
||||
"settings.error.intRange": "Enter a whole number from {min} to {max}",
|
||||
|
|
@ -436,8 +446,21 @@
|
|||
"terminal.tab.numbered": "Local ({n})",
|
||||
"terminal.tabs.label": "Terminals",
|
||||
"terminal.toolWindow.title": "Terminal",
|
||||
"theme.import.done": "Imported the theme {name}.",
|
||||
"theme.import.title": "Import Theme",
|
||||
"theme.lutraDark": "Lutra Dark",
|
||||
"theme.lutraLight": "Lutra Light",
|
||||
"theme.lutraPaper": "Paper",
|
||||
"theme.lutraPlumNight": "Plum Night",
|
||||
"theme.lutraReed": "Reed",
|
||||
"theme.lutraRiver": "River",
|
||||
"theme.notification.skipped": "Skipped the theme file {file}: {reason}",
|
||||
"theme.picker.current": "current",
|
||||
"theme.picker.dark": "Dark",
|
||||
"theme.picker.followsSystem": "Follows the light or dark preference of your operating system",
|
||||
"theme.picker.imported": "{mode}, imported",
|
||||
"theme.picker.light": "Light",
|
||||
"theme.picker.title": "Select Theme",
|
||||
"vcs.branchItem.detached": "Detached HEAD at {hash}. Click for branches.",
|
||||
"vcs.branchItem.label": "Git branch {branch}. Click for branches.",
|
||||
"vcs.branches.create": "Create",
|
||||
|
|
|
|||
|
|
@ -8,9 +8,13 @@
|
|||
* ones.
|
||||
* - **Errors:** a refused change keeps the error per key until the value
|
||||
* changes or another change succeeds; the dialog shows it inline.
|
||||
* - **Effects:** `editor.fontSize` drives `--lt-font-size-editor` (above
|
||||
* the theme's value, see `setTokenOverride`). `appearance.theme` needs
|
||||
* nothing here: the engine answers with `themeChanged`.
|
||||
* - **Effects:** the editor font settings drive theme tokens above the
|
||||
* theme's value (see `setTokenOverride`), live: `editor.fontSize` →
|
||||
* `--lt-font-size-editor`, `editor.fontFamily` → `--lt-font-mono` (with
|
||||
* {@link MONO_FALLBACK} behind it), `editor.lineHeight` →
|
||||
* `--lt-line-height-editor`. `appearance.theme` needs nothing here: the
|
||||
* engine answers with `themeChanged`; a change of it reloads the list,
|
||||
* since an import adds a value (C9 T1).
|
||||
* - **Text:** labels, descriptions, section names and enum value names are
|
||||
* catalog keys (`settings.<key>.label`, `settings.<key>.description`,
|
||||
* `settings.section.<id>`, `settings.<key>.value.<value>`); the engine
|
||||
|
|
@ -38,6 +42,8 @@ export interface SettingDef {
|
|||
default: SettingValue;
|
||||
/** Accepted values of an enum; empty otherwise. */
|
||||
enumValues: string[];
|
||||
/** Display names of enum values without a catalog key (imported themes), by value. */
|
||||
valueNames: Record<string, string>;
|
||||
/** Smallest value of an int, or null. */
|
||||
min: number | null;
|
||||
/** Largest value of an int, or null. */
|
||||
|
|
@ -68,6 +74,54 @@ export const FONT_SIZE_KEY = "editor.fontSize";
|
|||
/** Theme token the editor font size drives. */
|
||||
export const FONT_SIZE_TOKEN = "--lt-font-size-editor";
|
||||
|
||||
/** Key of the editor font family setting. */
|
||||
export const FONT_FAMILY_KEY = "editor.fontFamily";
|
||||
|
||||
/** Theme token the editor font family drives. */
|
||||
export const FONT_FAMILY_TOKEN = "--lt-font-mono";
|
||||
|
||||
/** Fonts behind a chosen family, as `font-mono` in `crates/engine/src/theme.rs`. */
|
||||
export const MONO_FALLBACK = 'ui-monospace, "Cascadia Code", Menlo, Consolas, monospace';
|
||||
|
||||
/** Key of the editor line height setting, in percent of the font size. */
|
||||
export const LINE_HEIGHT_KEY = "editor.lineHeight";
|
||||
|
||||
/** Theme token the editor line height drives. */
|
||||
export const LINE_HEIGHT_TOKEN = "--lt-line-height-editor";
|
||||
|
||||
/** Key of the theme setting. */
|
||||
export const THEME_KEY = "appearance.theme";
|
||||
|
||||
/**
|
||||
* The token value of an editor font setting, or null for the theme's.
|
||||
*
|
||||
* @param key - the setting.
|
||||
* @param value - its value; unchecked.
|
||||
* @returns the CSS value, or null when the value is the default or unusable.
|
||||
*/
|
||||
export function fontTokenValue(key: string, value: SettingValue | undefined): string | null {
|
||||
if (key === FONT_SIZE_KEY) {
|
||||
return typeof value === "number" && Number.isInteger(value) && value > 0 ? `${String(value)}px` : null;
|
||||
}
|
||||
if (key === LINE_HEIGHT_KEY) {
|
||||
return typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 300
|
||||
? String(value / 100)
|
||||
: null;
|
||||
}
|
||||
if (key === FONT_FAMILY_KEY) {
|
||||
const family = typeof value === "string" ? value.trim() : "";
|
||||
return family === "" || /[;{}<>\\]/.test(family) ? null : `${family}, ${MONO_FALLBACK}`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Each editor font setting and the token it drives. */
|
||||
const FONT_TOKENS: Readonly<Record<string, string>> = {
|
||||
[FONT_SIZE_KEY]: FONT_SIZE_TOKEN,
|
||||
[FONT_FAMILY_KEY]: FONT_FAMILY_TOKEN,
|
||||
[LINE_HEIGHT_KEY]: LINE_HEIGHT_TOKEN,
|
||||
};
|
||||
|
||||
/** Most settings read from `settings.list`; the rest are dropped. */
|
||||
export const MAX_SETTINGS = 1000;
|
||||
|
||||
|
|
@ -94,7 +148,7 @@ function toSettingDef(raw: unknown): SettingDef | null {
|
|||
return null;
|
||||
}
|
||||
const entry = raw as Record<string, unknown>;
|
||||
const { key, type, labelKey, descriptionKey, section, enumValues, min, max } = entry;
|
||||
const { key, type, labelKey, descriptionKey, section, enumValues, valueNames, min, max } = entry;
|
||||
if (
|
||||
typeof key !== "string" ||
|
||||
typeof labelKey !== "string" ||
|
||||
|
|
@ -110,11 +164,20 @@ function toSettingDef(raw: unknown): SettingDef | null {
|
|||
if (type === "enum" && values.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const names: Record<string, string> = {};
|
||||
if (typeof valueNames === "object" && valueNames !== null) {
|
||||
for (const [value, name] of Object.entries(valueNames as Record<string, unknown>)) {
|
||||
if (typeof name === "string" && values.includes(value)) {
|
||||
names[value] = clip(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
key,
|
||||
type,
|
||||
default: toScalar(entry.default),
|
||||
enumValues: values,
|
||||
valueNames: names,
|
||||
min: typeof min === "number" && Number.isFinite(min) ? min : null,
|
||||
max: typeof max === "number" && Number.isFinite(max) ? max : null,
|
||||
labelKey,
|
||||
|
|
@ -179,14 +242,15 @@ export function sectionLabel(id: string): string {
|
|||
|
||||
/**
|
||||
* The name of an enum value: `settings.<key>.value.<value>` with the value
|
||||
* in camel case (`lutra-dark` → `lutraDark`), or the value itself.
|
||||
* in camel case (`lutra-dark` → `lutraDark`), else the name the engine
|
||||
* sent (an imported theme), else the value itself.
|
||||
*
|
||||
* @param def - the setting.
|
||||
* @param value - one of its values.
|
||||
*/
|
||||
export function valueLabel(def: SettingDef, value: string): string {
|
||||
const name = value.replace(/[-_.\s]+([A-Za-z0-9])/g, (_m, c: string) => c.toUpperCase());
|
||||
return textOr(`settings.${def.key}.value.${name}`, value);
|
||||
return textOr(`settings.${def.key}.value.${name}`, def.valueNames[value] ?? value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -259,19 +323,15 @@ export const useSettingsStore = defineStore("settings", () => {
|
|||
|
||||
/**
|
||||
* Applies what a value change means outside the dialog: the editor font
|
||||
* size token.
|
||||
* tokens.
|
||||
*
|
||||
* @param key - the changed key.
|
||||
*/
|
||||
function applyEffect(key: string): void {
|
||||
if (key !== FONT_SIZE_KEY) {
|
||||
return;
|
||||
const token = FONT_TOKENS[key];
|
||||
if (token !== undefined) {
|
||||
setTokenOverride(token, fontTokenValue(key, values[key]));
|
||||
}
|
||||
const size = values[key];
|
||||
setTokenOverride(
|
||||
FONT_SIZE_TOKEN,
|
||||
typeof size === "number" && Number.isInteger(size) && size > 0 ? `${String(size)}px` : null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -408,6 +468,10 @@ export const useSettingsStore = defineStore("settings", () => {
|
|||
for (const key of keys) {
|
||||
Reflect.deleteProperty(errors, key);
|
||||
}
|
||||
if (keys.includes(THEME_KEY)) {
|
||||
void load();
|
||||
return;
|
||||
}
|
||||
void fetchValues(keys);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue