Skip to content

Commit 204fe2d

Browse files
author
Akos Kitta
committed
fix: ordered theme select options in dialog
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 51ed550 commit 204fe2d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

arduino-ide-extension/src/browser/theia/core/theming.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
ThemeService,
55
} from '@theia/core/lib/browser/theming';
66
import { nls } from '@theia/core/lib/common/nls';
7-
import type { Theme } from '@theia/core/lib/common/theme';
7+
import type { Theme, ThemeType } from '@theia/core/lib/common/theme';
88
import { injectable } from '@theia/core/shared/inversify';
99
import { ThemeServiceWithDB as TheiaThemeServiceWithDB } from '@theia/monaco/lib/browser/monaco-indexed-db';
1010

@@ -87,7 +87,7 @@ interface ThemeProvider {
8787

8888
/**
8989
* Returns with a list of built-in themes officially supported by IDE2 (https://github.com/arduino/arduino-ide/issues/1283).
90-
* If the `currentTheme` is not a built-in one, it will be appended to the array. Built-in themes come first, followed by any contributed one.
90+
* If the `currentTheme` is not a built-in one, it will be appended to the array. Built-in themes come first (in light, dark, HC dark order), followed by any contributed one.
9191
*/
9292
export function userConfigurableThemes(service: ThemeService): Theme[];
9393
export function userConfigurableThemes(provider: ThemeProvider): Theme[];
@@ -104,14 +104,21 @@ export function userConfigurableThemes(
104104
const currentTheme = provider.currentTheme();
105105
return provider
106106
.themes()
107-
.map((theme, index) => ({ ...theme, index }))
108107
.filter((theme) => isBuiltInTheme(theme) || currentTheme.id === theme.id)
109108
.sort((left, right) => {
110109
const leftBuiltIn = isBuiltInTheme(left);
111110
const rightBuiltIn = isBuiltInTheme(right);
112111
if (leftBuiltIn === rightBuiltIn) {
113-
return left.index - right.index;
112+
return themeTypeComparator(left, right);
114113
}
115114
return leftBuiltIn ? -1 : 1;
116115
});
117116
}
117+
118+
const themeTypeOrder: Record<ThemeType, number> = {
119+
light: 0,
120+
dark: 1,
121+
hc: 2,
122+
};
123+
const themeTypeComparator = (left: Theme, right: Theme) =>
124+
themeTypeOrder[left.type] - themeTypeOrder[right.type];

arduino-ide-extension/src/test/browser/theming.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('theming', () => {
2828
it('if the current theme is a built-in theme, the result does not contain any contributed theme', () => {
2929
const actual = userConfigurableThemes({
3030
themes: () => [
31-
ArduinoThemes.light,
3231
ArduinoThemes.dark,
32+
ArduinoThemes.light,
3333
testTheme,
3434
BuiltinThemeProvider.hcTheme,
3535
anotherTestTheme,
@@ -54,9 +54,9 @@ describe('theming', () => {
5454
currentTheme: () => testTheme,
5555
});
5656
expect(actual.length).to.be.equal(4);
57-
expect(actual[0].id).to.be.equal(BuiltinThemeProvider.hcTheme.id);
57+
expect(actual[0].id).to.be.equal(ArduinoThemes.light.id);
5858
expect(actual[1].id).to.be.equal(ArduinoThemes.dark.id);
59-
expect(actual[2].id).to.be.equal(ArduinoThemes.light.id);
59+
expect(actual[2].id).to.be.equal(BuiltinThemeProvider.hcTheme.id);
6060
expect(actual[3].id).to.be.equal(testTheme.id);
6161
});
6262
});

0 commit comments

Comments
 (0)