Skip to content

Commit e047b9a

Browse files
authored
refactor(editor-monaco): consolidate themes (#3980)
1 parent bffffa4 commit e047b9a

File tree

13 files changed

+417
-454
lines changed

13 files changed

+417
-454
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"import/no-unresolved": [2, {
4343
"ignore": [
4444
// https://github.com/import-js/eslint-plugin-import/issues/1810
45-
"^monaco-languageclient\/monaco-converter$"
45+
"^monaco-languageclient\/monaco-converter$",
46+
"^vscode\/services$"
4647
]
4748
}]
4849
}

src/plugins/editor-monaco/actions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const EDITOR_UPDATE_THEME = 'editor_update_theme';
1+
export const EDITOR_SET_THEME = 'editor_set_theme';
22

33
export const EDITOR_SET_MARKERS = 'editor_set_markers';
44
export const EDITOR_APPEND_MARKERS = 'editor_append_markers';
@@ -12,10 +12,10 @@ export const EDITOR_CLEAR_REQUEST_JUMP_TO_EDITOR_MARKER =
1212

1313
export const EDITOR_SET_LANGUAGE = 'editor_set_language';
1414

15-
export const updateEditorTheme = (theme = 'my-vs-dark') => {
15+
export const setTheme = (theme = 'my-vs-dark') => {
1616
return {
1717
payload: theme,
18-
type: EDITOR_UPDATE_THEME,
18+
type: EDITOR_SET_THEME,
1919
};
2020
};
2121

src/plugins/editor-monaco/after-load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StandaloneServices, IStorageService } from 'vscode/services'; // eslint-disable-line import/no-unresolved
1+
import { StandaloneServices, IStorageService } from 'vscode/services';
22

33
const afterLoad = () => {
44
/**

src/plugins/editor-monaco/components/MonacoEditor/MonacoEditor.jsx

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
33
import * as monaco from 'monaco-editor';
44
import noop from 'lodash/noop.js';
55

6-
import getStyleMetadataLight, { themes as themesLight } from '../../utils/monaco-theme-light.js';
7-
import getStyleMetadataDark, { themes as themesDark } from '../../utils/monaco-theme-dark.js';
6+
import seVsDarkTheme from '../../themes/se-vs-dark.js';
7+
import seVsLightTheme from '../../themes/se-vs-light.js';
88
import { dereference } from '../../utils/monaco-action-apidom-deref.js';
99
import { requestGetJsonPointerPosition } from '../../utils/monaco-jump-from-path-to-line.js';
1010
import { useMount, useUpdate, useSmoothResize } from './hooks.js';
@@ -90,8 +90,8 @@ const MonacoEditor = ({
9090

9191
// defining the custom themes and setting the active one
9292
useMount(() => {
93-
monaco.editor.defineTheme('my-vs-dark', themesDark.seVsDark);
94-
monaco.editor.defineTheme('my-vs-light', themesLight.seVsLight);
93+
monaco.editor.defineTheme('se-vs-dark', seVsDarkTheme);
94+
monaco.editor.defineTheme('se-vs-light', seVsLightTheme);
9595
});
9696

9797
// update language
@@ -163,7 +163,7 @@ const MonacoEditor = ({
163163
// then clear the request itself
164164
onClearRequestJumpToMarker();
165165
} else {
166-
// just clear the request anyways
166+
// just clear the request anyway
167167
onClearRequestJumpToMarker();
168168
}
169169
}
@@ -188,35 +188,7 @@ const MonacoEditor = ({
188188

189189
// settings the theme if changed
190190
useEffect(() => {
191-
// START dev demo test unrelated to the setTheme
192-
// async function findMarkerPosition() {
193-
// const mockPath =
194-
// '/channels/smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured'; // asyncapi
195-
// // via apidom-ls
196-
// const foundMarkerPosition = await requestGetJsonPointerPosition(editorRef.current, mockPath);
197-
// console.log('mock...foundMarkerPosition', foundMarkerPosition);
198-
// if (foundMarkerPosition?.data) {
199-
// onSetRequestJumpToMarker(foundMarkerPosition.data);
200-
// onClearRequestJumpToMarker();
201-
// } else {
202-
// onClearRequestJumpToMarker();
203-
// }
204-
// }
205-
// if (editorRef?.current?.getModel) {
206-
// findMarkerPosition();
207-
// }
208-
// END dev demo test
209-
if (theme === 'vs-dark') {
210-
monaco.editor.setTheme('vs-dark');
211-
// eslint-disable-next-line no-underscore-dangle
212-
editorRef.current._themeService._theme.getTokenStyleMetadata = getStyleMetadataDark;
213-
} else if (['vs-light', 'vs'].includes(theme)) {
214-
monaco.editor.setTheme('vs');
215-
// eslint-disable-next-line no-underscore-dangle
216-
editorRef.current._themeService._theme.getTokenStyleMetadata = getStyleMetadataLight;
217-
} else {
218-
monaco.editor.setTheme(theme);
219-
}
191+
monaco.editor.setTheme(theme);
220192
}, [theme]);
221193

222194
// register listener for validation markers

src/plugins/editor-monaco/components/MonacoEditor/MonacoEditorContainer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
44
import MonacoEditor from './MonacoEditor.jsx';
55

66
const MonacoEditorContainer = ({ editorActions, editorSelectors, isReadOnly }) => {
7-
const theme = editorSelectors.selectEditorTheme();
7+
const theme = editorSelectors.selectTheme();
88
const jumpToMarker = editorSelectors.selectEditorJumpToMarker();
99
const requestJumpToMarker = editorSelectors.selectEditorRequestJumpToMarker();
1010
const value = editorSelectors.selectContent();
@@ -87,7 +87,7 @@ MonacoEditorContainer.propTypes = {
8787
editorSelectors: PropTypes.shape({
8888
selectLanguage: PropTypes.func.isRequired,
8989
selectContent: PropTypes.func.isRequired,
90-
selectEditorTheme: PropTypes.func.isRequired,
90+
selectTheme: PropTypes.func.isRequired,
9191
selectEditorJumpToMarker: PropTypes.func.isRequired,
9292
selectEditorRequestJumpToMarker: PropTypes.func.isRequired,
9393
}).isRequired,

src/plugins/editor-monaco/components/ThemeSelectionIcon.jsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { MoonIcon, SunIcon } from '@primer/octicons-react';
44

5-
const themeList = ['vs', 'vs-light', 'vs-dark', 'my-vs-light', 'my-vs-dark'];
6-
75
const ThemeSelectionIcon = ({ editorSelectors, editorActions }) => {
8-
const theme = editorSelectors.selectEditorTheme();
6+
const theme = editorSelectors.selectTheme();
97

108
const handleChange = (newTheme) => () => {
11-
if (themeList.includes(newTheme)) {
12-
editorActions.updateEditorTheme(newTheme);
13-
}
9+
editorActions.setTheme(newTheme);
1410
};
1511

16-
return theme === 'vs' || theme === 'vs-light' || theme === 'my-vs-light' ? (
12+
return theme === 'se-vs-dark' ? (
1713
<div className="swagger-editor__generic-padding-thin-top-bottom">
1814
<button
1915
type="button"
2016
className="swagger-editor__editor-pane-bar-control"
21-
onClick={handleChange('my-vs-dark')}
17+
onClick={handleChange('se-vs-light')}
2218
>
23-
<MoonIcon size="small" aria-label="Dark theme" />
19+
<SunIcon size="small" aria-label="Light theme" />
2420
</button>
2521
</div>
2622
) : (
2723
<div className="swagger-editor__generic-padding-thin-top-bottom">
2824
<button
2925
type="button"
3026
className="swagger-editor__editor-pane-bar-control"
31-
onClick={handleChange('my-vs-light')}
27+
onClick={handleChange('se-vs-dark')}
3228
>
33-
<SunIcon size="small" aria-label="Light theme" />
29+
<MoonIcon size="small" aria-label="Dark theme" />
3430
</button>
3531
</div>
3632
);
3733
};
3834

3935
ThemeSelectionIcon.propTypes = {
40-
editorActions: PropTypes.oneOfType([PropTypes.object]).isRequired,
41-
editorSelectors: PropTypes.oneOfType([PropTypes.object]).isRequired,
36+
editorActions: PropTypes.shape({
37+
setTheme: PropTypes.func.isRequired,
38+
}).isRequired,
39+
editorSelectors: PropTypes.shape({
40+
selectTheme: PropTypes.func.isRequired,
41+
}).isRequired,
4242
};
4343

4444
export default ThemeSelectionIcon;

src/plugins/editor-monaco/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ThemeSelectionIcon from './components/ThemeSelectionIcon.jsx';
66
import EditorPaneBarTopWrapper from './wrap-components/EditorPaneBarTopWrapper.jsx';
77
import EditorPaneBarBottomWrapper from './wrap-components/EditorPaneBarBottomWrapper.jsx';
88
import {
9-
updateEditorTheme,
9+
setTheme,
1010
setMarkers,
1111
setLanguage,
1212
appendMarkers,
@@ -18,7 +18,7 @@ import {
1818
} from './actions.js';
1919
import reducers from './reducers.js';
2020
import {
21-
selectEditorTheme,
21+
selectTheme,
2222
selectMarkers,
2323
selectEditorJumpToMarker,
2424
selectEditorRequestJumpToMarker,
@@ -44,7 +44,7 @@ const EditorMonacoPlugin = () => ({
4444
statePlugins: {
4545
editor: {
4646
actions: {
47-
updateEditorTheme,
47+
setTheme,
4848
setMarkers,
4949
appendMarkers,
5050
clearMarkers,
@@ -56,7 +56,7 @@ const EditorMonacoPlugin = () => ({
5656
},
5757
reducers,
5858
selectors: {
59-
selectEditorTheme,
59+
selectTheme,
6060
selectMarkers,
6161
selectEditorJumpToMarker,
6262
selectEditorRequestJumpToMarker,

src/plugins/editor-monaco/reducers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fromJS, List } from 'immutable';
22

33
import {
4-
EDITOR_UPDATE_THEME,
4+
EDITOR_SET_THEME,
55
EDITOR_SET_MARKERS,
66
EDITOR_CLEAR_MARKERS,
77
EDITOR_APPEND_MARKERS,
@@ -13,8 +13,8 @@ import {
1313
} from './actions.js';
1414

1515
const reducers = {
16-
[EDITOR_UPDATE_THEME]: (state, action) => {
17-
return state.set('editorTheme', action.payload);
16+
[EDITOR_SET_THEME]: (state, action) => {
17+
return state.set('theme', action.payload);
1818
},
1919
[EDITOR_SET_MARKERS]: (state, action) => {
2020
return state.set('markers', fromJS(action.payload));
@@ -43,7 +43,7 @@ const reducers = {
4343
return state.set('editorRequestJumpToMarker', action.payload);
4444
},
4545
[EDITOR_SET_LANGUAGE]: (state, action) => {
46-
return state.set('editorLanguage', action.payload);
46+
return state.set('language', action.payload);
4747
},
4848
};
4949

src/plugins/editor-monaco/selectors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createSelector } from 'reselect';
22
import { List } from 'immutable';
33

4-
export const selectEditorTheme = (state) => state.get('editorTheme') || 'my-vs-dark';
4+
export const selectTheme = (state) => state.get('theme', 'se-vs-dark');
55

66
export const selectMarkers = createSelector(
77
(state) => state.get('markers', List()),
@@ -15,6 +15,6 @@ export const selectEditorJumpToMarker = createSelector(
1515
}
1616
);
1717

18-
export const selectLanguage = (state) => state.get('editorLanguage', 'plaintext');
18+
export const selectLanguage = (state) => state.get('language', 'plaintext');
1919

2020
export const selectEditorRequestJumpToMarker = (state) => state.get('editorRequestJumpToMarker');

0 commit comments

Comments
 (0)