Skip to content

Commit 5c0a3b2

Browse files
Merge pull request #733 from lukecotter/feat-custom-themes-label
2 parents bfb9e46 + dd7c9b5 commit 5c0a3b2

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

lana/src/commands/SwitchTimelineTheme.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,21 @@ export class SwitchTimelineTheme {
3333

3434
private static async command(_context: Context, _uri: Uri): Promise<void> {
3535
const config = getConfig();
36-
const customThemesNames = Object.keys(config.timeline.customThemes || {});
37-
const allThemeNames = Array.from(new Set(THEMES.concat(customThemesNames))).sort();
3836

39-
const items = allThemeNames.map((label) => ({
37+
const items = THEMES.map((label) => ({
4038
label,
4139
description: label === DEFAULT_THEME ? 'default' : '',
4240
}));
4341

42+
const builtInThemesNames = new Set(THEMES);
43+
for (const customThemeName of Object.keys(config.timeline.customThemes ?? {})) {
44+
if (!builtInThemesNames.has(customThemeName)) {
45+
items.push({ label: customThemeName, description: 'custom' });
46+
}
47+
}
48+
49+
items.sort((a, b) => a.label.localeCompare(b.label));
50+
4451
// Create a QuickPick that allows custom text
4552
const pick = window.createQuickPick();
4653
pick.items = items;

lana/src/commands/__tests__/SwitchTimelineTheme.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ describe('SwitchTimelineTheme', () => {
133133
await command.run({} as never);
134134

135135
const items = mockQuickPick.items;
136-
expect(items.some((i) => i.label === 'My Custom Theme')).toBe(true);
137-
expect(items.some((i) => i.label === 'Another Theme')).toBe(true);
136+
const myCustom = items.find((i) => i.label === 'My Custom Theme');
137+
const another = items.find((i) => i.label === 'Another Theme');
138+
expect(myCustom).toBeDefined();
139+
expect(myCustom?.description).toBe('custom');
140+
expect(another).toBeDefined();
141+
expect(another?.description).toBe('custom');
138142
});
139143

140144
it('should sort themes alphabetically', async () => {
@@ -172,6 +176,18 @@ describe('SwitchTimelineTheme', () => {
172176
expect(defaultItem?.description).toBe('default');
173177
});
174178

179+
it('should not mark non-default built-in themes as custom', async () => {
180+
const mockContext = createMockContext();
181+
const command = SwitchTimelineTheme.getCommand(
182+
mockContext as unknown as import('../../Context.js').Context,
183+
);
184+
185+
await command.run({} as never);
186+
187+
const draculaItem = mockQuickPick.items.find((i) => i.label === 'Dracula');
188+
expect(draculaItem?.description).toBe('');
189+
});
190+
175191
it('should deduplicate themes when custom theme has same name as preset', async () => {
176192
mockGetConfig.mockReturnValue({
177193
timeline: {

0 commit comments

Comments
 (0)