Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lana/src/commands/SwitchTimelineTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ export class SwitchTimelineTheme {

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

const items = allThemeNames.map((label) => ({
const items = THEMES.map((label) => ({
label,
description: label === DEFAULT_THEME ? 'default' : '',
}));

const builtInThemesNames = new Set(THEMES);
for (const customThemeName of Object.keys(config.timeline.customThemes ?? {})) {
if (!builtInThemesNames.has(customThemeName)) {
items.push({ label: customThemeName, description: 'custom' });
}
}

items.sort((a, b) => a.label.localeCompare(b.label));

// Create a QuickPick that allows custom text
const pick = window.createQuickPick();
pick.items = items;
Expand Down
20 changes: 18 additions & 2 deletions lana/src/commands/__tests__/SwitchTimelineTheme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ describe('SwitchTimelineTheme', () => {
await command.run({} as never);

const items = mockQuickPick.items;
expect(items.some((i) => i.label === 'My Custom Theme')).toBe(true);
expect(items.some((i) => i.label === 'Another Theme')).toBe(true);
const myCustom = items.find((i) => i.label === 'My Custom Theme');
const another = items.find((i) => i.label === 'Another Theme');
expect(myCustom).toBeDefined();
expect(myCustom?.description).toBe('custom');
expect(another).toBeDefined();
expect(another?.description).toBe('custom');
});

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

it('should not mark non-default built-in themes as custom', async () => {
const mockContext = createMockContext();
const command = SwitchTimelineTheme.getCommand(
mockContext as unknown as import('../../Context.js').Context,
);

await command.run({} as never);

const draculaItem = mockQuickPick.items.find((i) => i.label === 'Dracula');
expect(draculaItem?.description).toBe('');
});

it('should deduplicate themes when custom theme has same name as preset', async () => {
mockGetConfig.mockReturnValue({
timeline: {
Expand Down
Loading