Skip to content

Commit eb04c0e

Browse files
committed
Update monaco.ts
1 parent 3110aeb commit eb04c0e

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/lib/monaco.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,85 @@
22
import { loader } from '@monaco-editor/react';
33
import * as monaco from 'monaco-editor';
44

5-
// Register YAML basic language (syntax highlighting only) to avoid LSP worker integration
65
import 'monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js';
76

87
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
98

9+
import YamlWorker from 'monaco-yaml/yaml.worker?worker';
10+
1011
// Use ESM monaco to avoid loading AMD loader from CDN
1112
loader.config({ monaco });
1213

1314
export const GITHUB_LIGHT_DEFAULT = 'github-light-default';
1415
export const GITHUB_DARK_DEFAULT = 'github-dark-default';
1516

16-
// Inlined GitHub Light Default editor colors (subset focused on Monaco editor UI)
1717
const GITHUB_LIGHT_EDITOR_COLORS: monaco.editor.IColors = {
1818
'editor.foreground': '#1f2328',
1919
'editor.background': '#ffffff',
2020
'editorWidget.background': '#f6f8fa',
2121
'editor.lineHighlightBackground': '#eaeef2',
2222
'editorCursor.foreground': '#0969da',
23-
'editor.selectionBackground': '#0969da33', // 20% opacity
24-
'editor.inactiveSelectionBackground': '#0969da12', // 7% opacity
25-
'editor.selectionHighlightBackground': '#1a7f3740', // 25% opacity
23+
'editor.selectionBackground': '#0969da33',
24+
'editor.inactiveSelectionBackground': '#0969da12',
25+
'editor.selectionHighlightBackground': '#1a7f3740',
2626
'editorLineNumber.foreground': '#8c959f',
2727
'editorLineNumber.activeForeground': '#1f2328',
28-
'editorIndentGuide.background': '#1f23281f', // 12% opacity
29-
'editorIndentGuide.activeBackground': '#1f23283d', // 24% opacity
28+
'editorIndentGuide.background': '#1f23281f',
29+
'editorIndentGuide.activeBackground': '#1f23283d',
3030
'editorGutter.background': '#ffffff',
3131
'editorHoverWidget.background': '#f6f8fa',
3232
'editorHoverWidget.border': '#d0d7de',
3333
'editorSuggestWidget.background': '#f6f8fa',
3434
'editorSuggestWidget.border': '#d0d7de',
3535
'editorWidget.border': '#d0d7de',
3636
'editorWhitespace.foreground': '#d0d7de',
37-
'editor.wordHighlightBackground': '#afb8c180', // 50% opacity
38-
'editor.wordHighlightStrongBackground': '#afb8c14d', // 30% opacity
37+
'editor.wordHighlightBackground': '#afb8c180',
38+
'editor.wordHighlightStrongBackground': '#afb8c14d',
3939
};
4040

41-
// Inlined GitHub Dark Default editor colors (subset focused on Monaco editor UI)
4241
const GITHUB_DARK_EDITOR_COLORS: monaco.editor.IColors = {
4342
'editor.foreground': '#e6edf3',
4443
'editor.background': '#0d1117',
4544
'editorWidget.background': '#161b22',
4645
'editor.lineHighlightBackground': '#161b22',
4746
'editorCursor.foreground': '#2f81f7',
48-
'editor.selectionBackground': '#2f81f733', // 20% opacity
49-
'editor.inactiveSelectionBackground': '#2f81f712', // 7% opacity
50-
'editor.selectionHighlightBackground': '#2ea04340', // 25% opacity
47+
'editor.selectionBackground': '#2f81f733',
48+
'editor.inactiveSelectionBackground': '#2f81f712',
49+
'editor.selectionHighlightBackground': '#2ea04340',
5150
'editorLineNumber.foreground': '#6e7681',
5251
'editorLineNumber.activeForeground': '#e6edf3',
53-
'editorIndentGuide.background': '#e6edf31f', // 12% opacity
54-
'editorIndentGuide.activeBackground': '#e6edf33d', // 24% opacity
52+
'editorIndentGuide.background': '#e6edf31f',
53+
'editorIndentGuide.activeBackground': '#e6edf33d',
5554
'editorGutter.background': '#0d1117',
5655
'editorHoverWidget.background': '#161b22',
5756
'editorHoverWidget.border': '#30363d',
5857
'editorSuggestWidget.background': '#161b22',
5958
'editorSuggestWidget.border': '#30363d',
6059
'editorWidget.border': '#30363d',
6160
'editorWhitespace.foreground': '#484f58',
62-
'editor.wordHighlightBackground': '#6e768180', // 50% opacity
63-
'editor.wordHighlightStrongBackground': '#6e76814d', // 30% opacity
61+
'editor.wordHighlightBackground': '#6e768180',
62+
'editor.wordHighlightStrongBackground': '#6e76814d',
6463
};
6564

6665
export const configureMonaco = () => {
67-
self.MonacoEnvironment = {
68-
getWorker: (_: string) => new EditorWorker(),
66+
// Route YAML language to monaco-yaml worker, everything else to the default editor worker
67+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
68+
(self as any).MonacoEnvironment = {
69+
getWorker: (_: string, label: string) => {
70+
if (label === 'yaml') {
71+
return new YamlWorker();
72+
}
73+
return new EditorWorker();
74+
},
6975
};
7076

71-
// Register GitHub Light Default
7277
monaco.editor.defineTheme(GITHUB_LIGHT_DEFAULT, {
7378
base: 'vs',
7479
inherit: true,
7580
rules: [],
7681
colors: GITHUB_LIGHT_EDITOR_COLORS,
7782
});
7883

79-
// Register GitHub Dark Default
8084
monaco.editor.defineTheme(GITHUB_DARK_DEFAULT, {
8185
base: 'vs-dark',
8286
inherit: true,

0 commit comments

Comments
 (0)