feat(settings): preview locale and serialize UI scale application

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-09 12:04:54 +08:00
1 parent 004b27a3c2
commit a0cce8cc8f
9 files changed
+284 -20

No files matched your search

@@ -217,7 +217,7 @@ import { useConnectionStore } from "@/stores/connectionStore";
import { useSavedSqlStore } from "@/stores/savedSqlStore";
import { usePromptTemplateStore } from "@/stores/promptTemplateStore";
import { useTunnelProfileStore } from "@/stores/tunnelProfileStore";
import { currentLocale, setLocale, type Locale } from "@/i18n";
import { currentLocale, previewLocale, restoreLocalePreview, setLocale, type Locale } from "@/i18n";
import { SETTINGS_SEARCH_DEFINITIONS, TOOLBAR_VISIBILITY_ITEMS, createShortcutSettingsSearchDefinitions, resolveSettingsSearchEntries, searchSettings, toolbarVisibilityItemLabel, type SettingsCategory, type SettingsSearchEntry, type ToolbarVisibilityItem } from "@/lib/settings/settingsSearch";
import { LOCALE_OPTIONS } from "@/lib/app/localeOptions";
import { DEFAULT_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES, DEFAULT_WEB_DAV_REMOTE_PATH, normalizedWebDavAutoUploadInterval, writeWebDavAutoUploadFields } from "@/lib/webdav/webdavAutoUploadConfig";
@@ -274,6 +274,18 @@ function onUiFontFamilyOpenChange(open: boolean) {
}
}
function previewLocaleOption(locale: Locale) {
void previewLocale(locale);
}
function restoreLocaleOptionPreview() {
void restoreLocalePreview();
}
function onLocaleOpenChange(open: boolean) {
if (!open) restoreLocaleOptionPreview();
}
const appThemePaletteOptions = computed(
(): Array<{ value: AppThemePalette; label: string; previewColor: string }> =>
APP_THEME_PALETTES.map((palette) => ({
@@ -1442,6 +1454,7 @@ watch(
} else {
clearThemePalettePreview();
clearUiFontFamilyPreview();
restoreLocaleOptionPreview();
}
},
{ immediate: true },
@@ -1453,6 +1466,7 @@ watch(
if (isSettingsPage.value && !active) {
clearThemePalettePreview();
clearUiFontFamilyPreview();
restoreLocaleOptionPreview();
}
},
{ immediate: true },
@@ -2073,6 +2087,12 @@ function onLocaleChange(v: any) {
if (typeof v === "string") void setLocale(v as Locale);
}
function onUiScaleChange(value: unknown) {
const next = Number(value);
if (!Number.isFinite(next)) return;
editUiScale.value = next;
}
function onUpdateDownloadSourceChange(v: any) {
if (v === "official" || v === "cnb") editUpdateDownloadSource.value = v;
}
@@ -3669,6 +3689,7 @@ onMounted(() => {
onUnmounted(() => {
clearThemePalettePreview();
clearUiFontFamilyPreview();
restoreLocaleOptionPreview();
cleanupTableColumnTemplatePointerDrag();
cleanupTruncationObservers();
});
@@ -5650,7 +5671,7 @@ onUnmounted(() => {
<div class="flex h-9 items-end">
<Label class="whitespace-normal leading-tight">{{ t("settings.languageTitle") }}</Label>
</div>
<Select :model-value="currentLocale()" @update:model-value="onLocaleChange">
<Select :model-value="currentLocale()" @update:model-value="onLocaleChange" @update:open="onLocaleOpenChange">
<SelectTrigger class="h-8 w-full gap-0.5 px-0.5">
<SelectValue>
<span v-if="selectedLocaleOption" class="flex min-w-0 items-center gap-0.5">
@@ -5661,8 +5682,8 @@ onUnmounted(() => {
</span>
</SelectValue>
</SelectTrigger>
<SelectContent class="w-[150px]">
<SelectItem v-for="locale in LOCALE_OPTIONS" :key="locale.value" :value="locale.value">
<SelectContent class="w-[150px]" @pointerleave="restoreLocaleOptionPreview">
<SelectItem v-for="locale in LOCALE_OPTIONS" :key="locale.value" :value="locale.value" @pointerenter="previewLocaleOption(locale.value)" @focus="previewLocaleOption(locale.value)">
<div class="flex items-center gap-1">
<span class="inline-flex h-5 w-6 shrink-0 items-center justify-center text-sm font-medium leading-none">
{{ locale.flag }}
@@ -5719,15 +5740,7 @@ onUnmounted(() => {
</HelpTooltip>
</div>
</div>
<Select
:model-value="String(editUiScale)"
@update:model-value="
(value: any) => {
const next = Number(value);
if (Number.isFinite(next)) editUiScale = next;
}
"
>
<Select :model-value="String(editUiScale)" @update:model-value="onUiScaleChange">
<SelectTrigger class="h-8 w-full">
<SelectValue>{{ Math.round(editUiScale * 100) }}%</SelectValue>
</SelectTrigger>
@@ -5773,6 +5786,7 @@ onUnmounted(() => {
:trigger-class="appearanceFontSearchTriggerClass"
:trigger-icon-class="appearanceFontSearchTriggerIconClass"
content-class="w-[var(--reka-popover-trigger-width)] min-w-[260px]"
:content-style="{ fontFamily: editUiFontFamily || DEFAULT_UI_FONT_FAMILY }"
@update:model-value="onUiFontFamilyChange"
@update:open="onUiFontFamilyOpenChange"
@option-hover="previewUiFontOption"
@@ -17,5 +17,20 @@ describe("EditorSettingsDialog preview cleanup", () => {
expect(dialogSource).toContain("if (isSettingsPage.value && !active)");
expect(dialogSource).toContain("clearThemePalettePreview();");
expect(dialogSource).toContain("clearUiFontFamilyPreview();");
expect(dialogSource).toContain("restoreLocaleOptionPreview();");
});
it("keeps language hover preview while scale stays an unapplied draft", () => {
expect(dialogSource).toContain('@update:open="onLocaleOpenChange"');
expect(dialogSource).toContain('@pointerleave="restoreLocaleOptionPreview"');
expect(dialogSource).toContain('@pointerenter="previewLocaleOption(locale.value)"');
expect(dialogSource).toContain('@update:model-value="onUiScaleChange"');
expect(dialogSource).not.toContain("useUiScalePreview");
expect(dialogSource).not.toContain("previewUiScaleOption");
expect(dialogSource).not.toContain("createUiScalePreviewRestore");
expect(appSource).toContain("createUiScaleApplyQueue");
expect(appSource).not.toContain("useUiScalePreview");
expect(appSource).toContain("() => settingsStore.editorSettings.uiScale");
expect(appSource).toContain("applyUiScale(scale)");
});
});