fix(editor): keep custom theme entry point when customThemes is empty
This commit is contained in:
1 parent
c737fde538
commit
7aa69a0e5e
5 files changed
+199
-50
No files matched your search
@@ -4,6 +4,7 @@ import { isProxy } from "vue";
|
||||
import {
|
||||
AI_PROVIDER_PARTNER_PRESETS,
|
||||
AI_PROVIDER_PRESETS,
|
||||
DEFAULT_CUSTOM_THEMES,
|
||||
DEFAULT_EDITOR_SETTINGS,
|
||||
EXECUTE_MODE_CURRENT_DEFAULT_VERSION,
|
||||
SIDEBAR_BROWSE_OBJECTS_MIGRATION_VERSION,
|
||||
@@ -130,6 +131,37 @@ describe("normalizeEditorSettings", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes customThemes when empty or absent by seeding DEFAULT_CUSTOM_THEMES", () => {
|
||||
// When customThemes is an empty array
|
||||
const normalizedEmpty = normalizeEditorSettings({ customThemes: [] });
|
||||
expect(normalizedEmpty.customThemes).toEqual(DEFAULT_CUSTOM_THEMES);
|
||||
expect(normalizedEmpty.activeCustomThemeId).toBe("default");
|
||||
|
||||
// When customThemes is absent
|
||||
const normalizedAbsent = normalizeEditorSettings({});
|
||||
expect(normalizedAbsent.customThemes).toEqual(DEFAULT_CUSTOM_THEMES);
|
||||
expect(normalizedAbsent.activeCustomThemeId).toBe("default");
|
||||
|
||||
// When customThemes has invalid activeCustomThemeId, fall back to first theme id
|
||||
const customList = [{ id: "my-theme", name: "My Theme", colors: DEFAULT_CUSTOM_THEMES[0].colors, ddlColors: DEFAULT_CUSTOM_THEMES[0].ddlColors }];
|
||||
const normalizedInvalidActive = normalizeEditorSettings({
|
||||
customThemes: customList,
|
||||
activeCustomThemeId: "nonexistent",
|
||||
});
|
||||
expect(normalizedInvalidActive.customThemes).toHaveLength(1);
|
||||
expect(normalizedInvalidActive.activeCustomThemeId).toBe("my-theme");
|
||||
|
||||
// When legacy customThemeColors is provided and customThemes is empty
|
||||
const legacyColors = { ...DEFAULT_CUSTOM_THEMES[0].colors, keyword: "#ff0000" };
|
||||
const normalizedLegacy = normalizeEditorSettings({
|
||||
customThemes: [],
|
||||
customThemeColors: legacyColors,
|
||||
});
|
||||
expect(normalizedLegacy.customThemes).toHaveLength(1);
|
||||
expect(normalizedLegacy.customThemes[0].id).toBe("migrated");
|
||||
expect(normalizedLegacy.customThemes[0].colors.keyword).toBe("#ff0000");
|
||||
});
|
||||
|
||||
it("defaults and bounds the persisted text filter panel height", () => {
|
||||
expect(normalizeEditorSettings({}).dataGridTextFilterPanelHeight).toBe(168);
|
||||
expect(normalizeEditorSettings({ dataGridTextFilterPanelHeight: 236.4 }).dataGridTextFilterPanelHeight).toBe(236);
|
||||
@@ -1186,6 +1218,15 @@ describe("settingsStore persisted settings initialization", () => {
|
||||
expect(saveEditorSettings).toHaveBeenCalledWith(expect.objectContaining({ fontSize: 17, theme: "xcode-dark", appLayout: "separated" }));
|
||||
});
|
||||
|
||||
it("seeds DEFAULT_CUSTOM_THEMES when updateEditorSettings receives empty customThemes", async () => {
|
||||
const { useSettingsStore } = await import("@/stores/settingsStore");
|
||||
const store = useSettingsStore();
|
||||
|
||||
store.updateEditorSettings({ customThemes: [] });
|
||||
expect(store.editorSettings.customThemes).toEqual(DEFAULT_CUSTOM_THEMES);
|
||||
expect(store.editorSettings.activeCustomThemeId).toBe("default");
|
||||
});
|
||||
|
||||
it("migrates the legacy filter-editor preference in incremental settings updates", async () => {
|
||||
const loadEditorSettings = vi.fn().mockResolvedValue({});
|
||||
const saveEditorSettings = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
@@ -1704,6 +1704,36 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
|
||||
const autoUpdateJdbc = typeof settings.autoUpdateJdbc === "boolean" ? settings.autoUpdateJdbc : legacyUpdateOptOut ? false : DEFAULT_EDITOR_SETTINGS.autoUpdateJdbc;
|
||||
const autoUpdateMcp = typeof settings.autoUpdateMcp === "boolean" ? settings.autoUpdateMcp : legacyUpdateOptOut ? false : DEFAULT_EDITOR_SETTINGS.autoUpdateMcp;
|
||||
const autoUpdatePlugins = typeof settings.autoUpdatePlugins === "boolean" ? settings.autoUpdatePlugins : legacyUpdateOptOut ? false : DEFAULT_EDITOR_SETTINGS.autoUpdatePlugins;
|
||||
const customThemes = (() => {
|
||||
if (Array.isArray(settings.customThemes) && settings.customThemes.length > 0) {
|
||||
return settings.customThemes.map((theme) => {
|
||||
const renamed = theme.name === "默认" ? { ...theme, name: "Custom" } : { ...theme };
|
||||
return {
|
||||
...renamed,
|
||||
colors: { ...DEFAULT_CUSTOM_THEME_COLORS, ...renamed.colors },
|
||||
ddlColors: {
|
||||
...DEFAULT_CUSTOM_THEME_DDL_COLORS,
|
||||
...(renamed as any).ddlColors,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
if (settings.customThemeColors && Object.keys(settings.customThemeColors).length > 0) {
|
||||
return [
|
||||
{
|
||||
id: "migrated",
|
||||
name: "Migrated",
|
||||
colors: {
|
||||
...DEFAULT_CUSTOM_THEME_COLORS,
|
||||
...settings.customThemeColors,
|
||||
},
|
||||
ddlColors: { ...DEFAULT_CUSTOM_THEME_DDL_COLORS },
|
||||
},
|
||||
];
|
||||
}
|
||||
return [...DEFAULT_CUSTOM_THEMES];
|
||||
})();
|
||||
const activeCustomThemeId = settings.activeCustomThemeId && customThemes.some((t) => t.id === settings.activeCustomThemeId) ? settings.activeCustomThemeId : (customThemes[0]?.id ?? "default");
|
||||
return {
|
||||
fontFamily: normalizeFontFamily(settings.fontFamily, DEFAULT_EDITOR_SETTINGS.fontFamily),
|
||||
fontSize: settings.fontSize ?? DEFAULT_EDITOR_SETTINGS.fontSize,
|
||||
@@ -1716,35 +1746,8 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
|
||||
...DEFAULT_CUSTOM_THEME_COLORS,
|
||||
...settings.customThemeColors,
|
||||
},
|
||||
customThemes: (() => {
|
||||
if (Array.isArray(settings.customThemes) && settings.customThemes.length > 0) {
|
||||
return settings.customThemes.map((theme) => {
|
||||
const renamed = theme.name === "默认" ? { ...theme, name: "Custom" } : { ...theme };
|
||||
return {
|
||||
...renamed,
|
||||
colors: { ...DEFAULT_CUSTOM_THEME_COLORS, ...renamed.colors },
|
||||
ddlColors: {
|
||||
...DEFAULT_CUSTOM_THEME_DDL_COLORS,
|
||||
...(renamed as any).ddlColors,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
return settings.customThemeColors
|
||||
? [
|
||||
{
|
||||
id: "migrated",
|
||||
name: "Migrated",
|
||||
colors: {
|
||||
...DEFAULT_CUSTOM_THEME_COLORS,
|
||||
...settings.customThemeColors,
|
||||
},
|
||||
ddlColors: { ...DEFAULT_CUSTOM_THEME_DDL_COLORS },
|
||||
},
|
||||
]
|
||||
: [];
|
||||
})(),
|
||||
activeCustomThemeId: settings.activeCustomThemeId ?? "default",
|
||||
customThemes,
|
||||
activeCustomThemeId,
|
||||
executeMode: hasCurrentExecuteModeDefault && (settings.executeMode === "all" || settings.executeMode === "current") ? settings.executeMode : DEFAULT_EDITOR_SETTINGS.executeMode,
|
||||
executeModeDefaultVersion,
|
||||
executeAllOnBlankLine: settings.executeAllOnBlankLine === true,
|
||||
@@ -2578,7 +2581,7 @@ export const useSettingsStore = defineStore("settings", () => {
|
||||
};
|
||||
}
|
||||
if (partial.customThemes !== undefined) {
|
||||
editorSettings.value.customThemes = Array.isArray(partial.customThemes) ? partial.customThemes : editorSettings.value.customThemes;
|
||||
editorSettings.value.customThemes = Array.isArray(partial.customThemes) && partial.customThemes.length > 0 ? partial.customThemes : [...DEFAULT_CUSTOM_THEMES];
|
||||
}
|
||||
if (partial.activeCustomThemeId !== undefined) {
|
||||
editorSettings.value.activeCustomThemeId = partial.activeCustomThemeId;
|
||||
@@ -2589,6 +2592,7 @@ export const useSettingsStore = defineStore("settings", () => {
|
||||
const activeTheme = themes.find((t) => t.id === activeId) || themes[0];
|
||||
if (activeTheme) {
|
||||
editorSettings.value.customThemeColors = { ...activeTheme.colors };
|
||||
editorSettings.value.activeCustomThemeId = activeTheme.id;
|
||||
}
|
||||
}
|
||||
if (partial.executeMode !== undefined) editorSettings.value.executeMode = partial.executeMode;
|
||||
|
||||
Reference in new issue
Block a user